Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NLog #158

Open
archanox opened this issue Sep 15, 2024 · 0 comments
Open

Add NLog #158

archanox opened this issue Sep 15, 2024 · 0 comments

Comments

@archanox
Copy link
Owner

archanox commented Sep 15, 2024

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");
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant