// Creates a new logging configuration var config = new NLog.Config.LoggingConfiguration(); // Adds a logging rule to write logs to a file var fileTarget = new NLog.Targets.FileTarget("logfile") { FileName = "log.txt" }; config.AddTarget(fileTarget); var rule = new NLog.Config.LoggingRule("*", NLog.LogLevel.Debug, fileTarget); config.AddRule(rule); // Creates a new logger with the configured rules NLog.LogManager.Configuration = config; var logger = NLog.LogManager.GetCurrentClassLogger(); // Logs a message to the configured targets logger.Info("Log message");
// Creates a new logging configuration var config = new NLog.Config.LoggingConfiguration(); // Adds a logging rule to write logs to the console var consoleTarget = new NLog.Targets.ConsoleTarget("console"); config.AddTarget(consoleTarget); var rule = new NLog.Config.LoggingRule("*", NLog.LogLevel.Error, consoleTarget); config.AddRule(rule); // Creates a new logger with the configured rules NLog.LogManager.Configuration = config; var logger = NLog.LogManager.GetCurrentClassLogger(); // Logs an error message to the configured targets logger.Error("Error message");
Install-Package NLog