【发布时间】:2019-05-21 13:17:33
【问题描述】:
我将目标日志从应用程序更改为“xxxx”。 我使用 powersheel 删除了源 并在“xxxx”下创建它。 当我写事件时,它不会出现在任何地方。
target = LogManager.Configuration.FindTargetByName("eventlog");
mode = config.RUN_MODE;
LogManager.Configuration.RemoveTarget("console");
((NLog.Targets.EventLogTarget)target).Log = "xxxx";
LoggingConfiguration loggingConfiguration = new LoggingConfiguration();
var asyncFileTarget = new AsyncTargetWrapper(target);
loggingConfiguration.AddTarget("eventlog", asyncFileTarget);
LogManager.Configuration = loggingConfiguration;
LogManager.Configuration.AddRule(LogLevel.Info, LogLevel.Fatal, target, mode, true);
LogManager.ReconfigExistingLoggers();
我使用 powershell 删除并添加了新日志和源(“xxxx”日志已创建):
Remove-EventLog -Source "mySource"
New-EventLog -LogName xxxx -Source "mySource code here
【问题讨论】:
-
PS:你可以使用
target = LogManager.Configuration.FindTargetByName<NLog.Targets.EventLogTarget>("eventlog");——这样可以节省演员表
标签: c# nlog event-viewer