Description for event id from source cannot be found

后端 未结 11 620
[愿得一人]
[愿得一人] 2020-11-29 01:55

When I write a log into windows event log, I get the event below, what\'s the root cause of this message, and how can I fix it? Many Thanks

The descri

11条回答
  •  再見小時候
    2020-11-29 02:20

    Improving on the answer by @Alex, I suggest the following:

                using (EventLog eventLog = new EventLog("Application"))
                {
                    //You cannot be sure if the current identity has permissions to register the event source.
                    try
                    {
                        if (System.Web.HttpRuntime.AppDomainAppId != null)
                        {
                            eventLog.Source = System.Web.HttpRuntime.AppDomainAppId;
                        }
                        else
                        {
                            eventLog.Source = Process.GetCurrentProcess().ProcessName;
                        }
                    }
                    catch (SecurityException)
                    {
                        eventLog.Source = "Application";
                    }
    
                    eventLog.WriteEntry("Log message example", EventLogEntryType.Information, 1000);
                }
    

    It is important here not to specify category parameter. If you do, and this is the same for the .NET Runtime so-called magic, the

    The description for Event ID <...> from source <...> cannot be found.

    is going to appear.

提交回复
热议问题