user1125567
user1125567

Reputation: 223

How to use NLog InternalLogger's method to write to NLog's internal log file

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

Answers (1)

Julian
Julian

Reputation: 36820

There is a tutorial here

In summary:

Enable the internal log, it's disabled by default

In config (nlog.config)

<nlog internalLogFile="c:\log.txt" internalLogLevel="Trace">

From code

Or from code:

// set internal log level
InternalLogger.LogLevel = LogLevel.Trace;

// enable internal logging to a file
InternalLogger.LogFile = "c:\\log.txt";

Upvotes: 15

Related Questions