I am using NLog logging mechanism in my application. The problem I face is when concurrent requests hit the application logging is done asynchronously and I am not able to identify which line belongs to which request. Is there a way in NLog to set the configuration to NLog itself logging a unique Request ID for each request ?
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<!-- add your targets here -->
<target xsi:type="File" name="file" fileName="E:\IBELogs\AirAvailability\AirAvailability.log" layout="${longdate} ${uppercase:${level}} ${message}" />
</targets>
<rules>
<!-- add your logging rules here -->
<logger name="*" minlevel="Trace" writeTo="file" />
</rules>
</nlog>
In NLog 4.1 ${activityid} was introduced, see here. I cannot say MSDN documentation is clear enough about its value, but so far, this is doing the trick for us, since every request in our webAPI application gets assigned a unique GUID and it is preserved through the entire request as we see the same value in several Nlog operations in the same request.
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