Reputation: 223
I am using NLog for logging in my library and I have created custom NLog Target to upload log entries to Azure Data Explorer. However, in the event that exception is encountered when uploading logs to Azure Data Explorer, I want to log an error message in my local log files.
However, I cannot use NLog's File Target for this error logging because by calling NLog's logging API again my custom Target will be invoked again, thus leading to infinite loop.
Thus, I want to use NLog's InternalLogger, which logs to NLog's internal log file, to log the upload error. However, when I used the below InternalLogger method it does not log to the internal log file.
InternalLogger.Error(e, msg);
The InternalLogger class is documented here
I am wondering if I am missing a configuration step or it is impossible to log to the NLog's internal log file?
Upvotes: 11
Views: 17829
Reputation: 36820
There is a tutorial here
In summary:
Enable the internal log, it's disabled by default
<nlog internalLogFile="c:\log.txt" internalLogLevel="Trace">
Or from code:
// set internal log level
InternalLogger.LogLevel = LogLevel.Trace;
// enable internal logging to a file
InternalLogger.LogFile = "c:\\log.txt";
Upvotes: 15