How to make Nlog with multiple target files with the same cached date-time in the file name

I am using Nlog 2.0 and I have 2 target files, one for our regular trace log and another for the error log. I use fileName="Error_${cached:cached=true:inner=${date:format=yyyyMMdd_HHmmss}}.txt"to give a consistent log file name for a single application run.

The problem is that the error log has a different time in the file name than the trace log because the error started to be logged much later. Right now, I resorted to sending an empty line at the beginning of the application to make both logs the same name. Is there a clear approach to this, i.e. One cached datetime for both purposes?

+3
source share
1 answer

NLog , . , , (, , , , ). , GlobalDiagnosticsContext, GlobalDiagnosticsContext, . - ...

, , , , :

NLog.GlobalDiagnosticsContext.Set("LogFileBase", DateTime.Now.ToString("yyyyMMdd_HHmmss"));

NLog.config :

fileName=${gdc:LogFileBase}.txt

.

+4

All Articles