Say you have C# trace messages all over an application. Something like:
Trace.TraceInformation("Service Started");
How do you automatically log this to an nLog target without having to add code like the following to all the classes that have trace messages?
using NLog;
private static Logger logger = LogManager.GetCurrentClassLogger();
Is there a way to do this without including traces produced by the .NET Framework itself, which this article demonstrates how to do?
You can use NLog's NLogTraceListener.
For completeness, here is the System.Diagnostics configuration (from the link above) to specify the NLogTraceListener:
You also need to configure NLog to tell it how to write the information once it moves from the System.Diagnostics.Trace to NLog:
This works for cases where there isn't an explicit source