![](/img/trans.png)
[英]Using nlog with ApplicationInsightsTelemetryWorkerService in .net core 3.1 console app
[英]Using NLog & Console Logging Together in .Net Core Console App
是否有任何实现在封装的记录器中使用 Nlog 和 .Net Core Console Logging。 例如,LoggingService 具有 Nlog factory 和 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.Logging.Extensions
的日志记录抽象:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.