3
votes

Can anyone please help with programmatic configuration of NLog internal logger?

I have various targets and the email target is not sending any email, although it does have the logging rule. So I was hoping to get more insight by enabling the internal log.

However I do programmatic configuration and did not find any resource that sets up the internal logger in code.

1

1 Answers

3
votes

Soms examples:

// enable internal logging to the console
NLog.Common.InternalLogger.LogToConsole = true;

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

// enable internal logging to a custom TextWriter
NLog.Common.InternalLogger.LogWriter = new StringWriter(); //e.g. TextWriter writer = File.CreateText("C:\\perl.txt")

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

See the NLog wiki

Internal logging can be configured through code by setting the following properties on InternalLogger class:

  • InternalLogger.LogLevel - specifies internal logging level
  • InternalLogger.LogFile - specifies name of the log file (null will disable logging to a file)
  • InternalLogger.LogToConsole - enables or disables logging to the console
  • InternalLogger.LogToConsoleError - enables or disables logging to the console error stream
  • InternalLogger.LogToTrace - enables or disables logging to System.Diagnostics.Trace (introduced in NLog 4.3)
  • InternalLogger.LogWriter - specifies a TextWriter object to use for logging
  • InternalLogger.IncludeTimestamp - enables or disables whether timestamps should be included in the internal log output (NLog 4.3+)