is there anyway to route System.Diagnostics.TraceSource logs through NLog in .NET Core? Using the NLog for .Net 4.5 we could setup NLog.NLogTraceListener in the app.config file as remonstrated in this post http://nlog-project.org/2010/09/02/routing-system-diagnostics-trace-and-system-diagnostics-tracesource-logs-through-nlog.html , but we dont have app.config in .net core anymore.
I've setup libraries that are outputting logs with TraceSource and I would like to route it to NLog targets.
Suggestions are welcome.
Try this. It worked for me.
using System.Diagnostics;
using NLog;
// Add this at the start of your app, like in Program.Main()
Trace.Listeners.Add(new NLogTraceListener());
// Now you can do...
Trace.TraceInformation("This message should go through NLog");
Of course, you'll need to properly configure NLog (NLog.config
) with the targets you need to see the messages.
Beware of target using xsi:type="Trace"
as this will lead to StackOverFlow Exception.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With