Skip to content

Add NLog #158

@archanox

Description

@archanox
using System;
using NLog;

class Program
{
    static void Main(string[] args)
    {
        // create a configuration instance
        var config = new NLog.Config.LoggingConfiguration();

        // create a console logging target
        var logConsole = new NLog.Targets.ConsoleTarget();
        // create a debug output logging target
        var logDebug = new NLog.Targets.OutputDebugStringTarget();

        // send logs with levels from Info to Fatal to the console
        config.AddRule(NLog.LogLevel.Info, NLog.LogLevel.Fatal, logConsole);
        // send logs with levels from Debug to Fatal to the console
        config.AddRule(NLog.LogLevel.Debug, NLog.LogLevel.Fatal, logDebug);

        // apply the configuration
        NLog.LogManager.Configuration = config;

        // create a logger
        var logger = LogManager.GetCurrentClassLogger();

        // logging
        logger.Trace("Trace message");
        logger.Debug("Debug message");
        logger.Info("Info message");
        logger.Warn("Warning message");
        logger.Error("Error message");
        logger.Fatal("Fatal message");
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions