stevejgordon / CorrelationId

An ASP.NET Core middleware component which synchronises a correlation ID for cross API request logging.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Storing Correlation Id in nlog

durnasaban opened this issue · comments

Hello,
How can I store the correlation id in nlog logs? Especially which keyword will provide to store correlation id in log sentences (below)?

<targets async="true">
    <target 
        xsi:type="Trace" 
        name="trace"
	layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message:truncate=250} ${exception:format=tostring}"/>
</targets>

Thank you

Hello,

  1. Set option AddToLoggingScope = true in ConfigureServices
    services.AddDefaultCorrelationId(options => options.AddToLoggingScope = true);
  2. To get correlationId in layout use
    ${mdlc:CorrelationId}