Search code examples
nlog

NLog, ASP.NET Core 5.0, difference between ClearProviders and using OutputDebugString


We are trying to get output into the Debug window in Visual Studio and the Events window in Diagnostic tools, however we are struggling with the NLog documentation and various posts

We have followed the guide in https://github.com/NLog/NLog/wiki/Getting-started-with-ASP.NET-Core-5 which includes this line

logging.ClearProviders();

If we do this then we didn't get any output in the Debug window or in the Visual Studio Diagnostics Events window

This answer suggests that this step is optional, and indeed removing it does appear to work: Show NLog output in debug window of asp.net core app

However, is that right? Also a few pages suggest that you can use the OutputDebugString target

My question. What's the difference, in .Net 5, between using the OutputDebugString target, the Debugger target, or just ignoring these and taking the ClearProviders line out?


Solution

  • NLog have no issue with living together with other logging-providers like AddDebug or AddConsole.

    When calling CreateDefaultBuilder then it will add the following providers:

    • Console
    • Debug
    • EventSource
    • EventLog - Windows only

    These can introduce a huge overhead, and will ofcourse ignore any filtering and output-layout configured for NLog. This is why most guides about AddNLog recommends to explictly call ClearProviders to avoid the drama of unexpected output in unexpected format.