我正在创建一个新的事件源并使用以下代码记录一条消息:
static void Main(string[] args)
{
if (!EventLog.SourceExists("My Log"))
{
EventLog.CreateEventSource("My Application", "My Log");
Console.WriteLine("Created new log \"My Log\"");
}
EventLog myLog = new EventLog("My Log");
myLog.Source = "My Application";
myLog.WriteEntry("Could not connect", EventLogEntryType.Error, 1001, 1);
}
创建了一个名为“我的日志”的自定义事件日志(如预期的那样),但消息记录在“应用程序”节点下。我做错了什么?
最佳答案
MSDN 中有如下注释:
If a source has already been mapped to a log and you remap it to a new log, you must restart the computer for the changes to take effect.
是否有可能在尝试您之前尝试写入应用程序日志的代码时,您现在需要重新启动才能“取消映射”该链接?
关于c# - Windows 事件日志 - 如何注册事件源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2667248/