Logging Unique Request IDs in text file NLog - To differentiate between requests
logging, nlog
Solution
You will have to generate your unique ID yourself. Then you can set the unique ID into the MDC and set the appropriate layout format that outputs your unique from MDC into the log.
Problem
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> ```