A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/nlog/nlog/wiki/Internal-Logging below:

Internal Logging · NLog/NLog Wiki · GitHub

When Troubleshooting NLog logging issues, then it is a good idea to enable internal logging, which often helps to identify where the problem is. Internal log output can be sent to a file, console window or both.

Enabling internal logging using configuration file

When you configure NLog using Configuration File, you can enable internal logging by setting the following attribute on the <nlog> element:

Here is an example of a configuration file which enables internal logging to a file:

<nlog internalLogFile="c:\nlog-internal.txt" internalLogLevel="Debug">
   <targets>
      <!-- target configuration here -->
   </targets>
   <rules>
      <!-- log routing rules -->
   </rules>
</nlog>

If not getting internal logger output, then make sure the NLog.config file has Build Action set. See also Logging-troubleshooting. Alternative try to activate Internal Logging programmatically.

Enabling internal logging programmatically

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

For best diagnostic output then make sure to enable NLog InternalLogger, before creating the first NLog Logger-object.

Here is an example of activating internal logging from code:

using NLog;
 
class Program
{
  static void Main()
  {
    // enable internal logging to the console
    NLog.Common.InternalLogger.LogToConsole = true;
 
    // enable internal logging to a file
    NLog.Common.InternalLogger.LogFile = "c:\\nlog-internal.txt"; // On Linux one can use "/home/nlog-internal.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 = NLog.LogLevel.Debug;

    // Perform test output, ensure first NLog Logger is created after InternalLogger is enabled.
    NLog.LogManager.GetLogger("Test").Info("Hello World");
  }
}
Enabling internal logging using environment variables

Before NLog 5.0 then environment variables and app.config settings would be automatically be applied on startup. But because of the startup overhead, then this has been disabled. Instead one now have to explicitly activate this behavior:

NLog.LogFactory.Setup().SetupInternalLogger(b => b.SetupFromEnvironmentVariables())

These are environment variables which control internal logging:

Description of InternalLogger LogLevels

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4