是否有任何实现可在封装的记录器中使用Nlog和.Net Core控制台记录。例如,LoggingService具有Nlog工厂和控制台日志记录功能。例如,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,您还可以通过NLog提供程序为Microsoft.Logging.Extensions
利用Microsoft的日志记录抽象: