Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

nlog

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

  • https://github.com/NLog/NLog/wiki/Debugger-target

  • https://github.com/NLog/NLog/wiki/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?

like image 282
tony Avatar asked Nov 20 '25 06:11

tony


1 Answers

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.

like image 129
Rolf Kristensen Avatar answered Nov 21 '25 21:11

Rolf Kristensen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!