I'm using ILogger<MyController>
to write logs using DI (see step 6)
I'm also using NLog EventProperties
I want to add traceId to all my logs in my controller automatically.
This is working:
logger.Info("Some log. TraceId:{traceId}", 123);
However, then I need to change all my log commands (a lot of them!), which is a pain.
If I do the following, it's not tread safe:
using NLog;
public class MyController : Controller
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public MyConstructor(Apilog apilog)
{
Logger.SetProperty("traceid", apilog.TraceId);
}
}
Is there some way to use SetProperty with ILogger<MyController>
?
Or some way of using NLog with SetProperty in a fast and thread safe way?
Many thanks in advance!