在 .Net Core 控制台应用程序中一起使用 NLog 和控制台日志记录
Using NLog & Console Logging Together in .Net Core Console App
是否有任何实现可以在封装的记录器中使用 Nlog 和 .Net Core 控制台记录。例如,LoggingService 具有 Nlog 工厂和 Console Logging 能力。
例如 LoggingService.Debug
写入 Nlog 日志文件和控制台。或者有没有其他方法可以处理这些类型的问题?
如果我误解了这个问题请告诉我,但 NLog 本身支持写入多个目标(即控制台和日志文件):
根据 https://github.com/nlog/nlog/wiki/Tutorial#configure-nlog-targets-for-output :
var config = new NLog.Config.LoggingConfiguration();
// Targets where to log to: File and Console
var logfile = new NLog.Targets.FileTarget("logfile") { FileName = "file.txt" };
var logconsole = new NLog.Targets.ConsoleTarget("logconsole");
// Rules for mapping loggers to targets
config.AddRule(LogLevel.Info, LogLevel.Fatal, logconsole);
config.AddRule(LogLevel.Debug, LogLevel.Fatal, logfile);
// Apply config
NLog.LogManager.Configuration = config;
借助 NET Core,您还可以通过 Microsoft.Logging.Extensions
:
的 NLog 提供程序利用 Microsoft 的日志记录抽象
是否有任何实现可以在封装的记录器中使用 Nlog 和 .Net Core 控制台记录。例如,LoggingService 具有 Nlog 工厂和 Console Logging 能力。
例如 LoggingService.Debug
写入 Nlog 日志文件和控制台。或者有没有其他方法可以处理这些类型的问题?
如果我误解了这个问题请告诉我,但 NLog 本身支持写入多个目标(即控制台和日志文件):
根据 https://github.com/nlog/nlog/wiki/Tutorial#configure-nlog-targets-for-output :
var config = new NLog.Config.LoggingConfiguration();
// Targets where to log to: File and Console
var logfile = new NLog.Targets.FileTarget("logfile") { FileName = "file.txt" };
var logconsole = new NLog.Targets.ConsoleTarget("logconsole");
// Rules for mapping loggers to targets
config.AddRule(LogLevel.Info, LogLevel.Fatal, logconsole);
config.AddRule(LogLevel.Debug, LogLevel.Fatal, logfile);
// Apply config
NLog.LogManager.Configuration = config;
借助 NET Core,您还可以通过 Microsoft.Logging.Extensions
: