我正在尝试使用事件日志写入一些调试信息,但无法使其工作。它提示无法找到事件源。我必须在操作系统上安装某些东西吗?
最佳答案
这是我根据我们的一个应用程序修改的代码。这可能会帮助您开始创作。
System.Diagnostics.EventLog eventLog1 = new System.Diagnostics.EventLog();
string eventLogName = "StackOverFlowEventName";
string eventLogSource = "StackOverFlowWebsite";
//This code HERE will create the Event for you
if (!System.Diagnostics.EventLog.SourceExists(eventLogSource))
{
System.Diagnostics.EventLog.CreateEventSource(eventLogSource, eventLogName);
}
eventLog1.Source = eventLogSource;
eventLog1.Log = eventLogName;
eventLog1.WriteEntry("This is a test");
关于c# - 事件日志代码错误无法找到事件源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/291169/