using NLogBuilder; using NLog; class Program { static void Main(string[] args) { NLogBuilder.ConfigureNLog("nlog.config"); ILogger logger = LogManager.GetCurrentClassLogger(); logger.Info("Hello, world!"); } }
using NLogBuilder; using NLog; using NLog.Config; using NLog.Targets; class Program { static void Main(string[] args) { var configBuilder = new LoggingConfiguration(); var consoleTarget = new ColoredConsoleTarget() { Layout = "${longdate}|${level:uppercase=true}|${logger}|${message}${onexception:|${exception:format=ToString}}" }; configBuilder.AddTarget("console", consoleTarget); configBuilder.AddRuleForAllLevels(consoleTarget); NLogBuilder.ConfigureNLog(configBuilder); ILogger logger = LogManager.GetCurrentClassLogger(); logger.Info("Hello, world!"); } }In this example, the ConfigureNLog method applies a programmatic configuration to the logging pipeline. A ColoredConsoleTarget is defined with a custom Layout, added to the configuration, and a rule is created to apply the target to all log levels. The result is that log messages will be written to the console in a colorful and informative format. Package library: NLog.Extensions.Logging. This package provides the NLogBuilder class for configuring NLog logging in the .NET Core logging system.