Windows Forms Event Log

I write to the event log from my Windows Forms application running on Windows 7 and I get this message in the event log:

The description for Event ID X from the source application could not be found. Either the component that raises this event is not installed on your local computer, or the installation is corrupted. You can install or repair the component on the local computer.

If the event occurred on another computer, the displayed information should have been saved with the event.

The following information was included in the event:

Exception Details

there is a message resource, but the message was not found in the table of lines / messages

My registration code:

public void Log(Exception exc)
{
    EventLog.WriteEntry(
        "Application", 
        exc.ToString(), 
        EventLogEntryType.Error, 
        100);
}

Windows Forms , . ASP.NET, XP Pro Windows Server 2003 -.

Windows 7 Windows Forms, , ? .

+3
3

", ". , , "", . ( , , Windows: , ..?)

, :

public void Log(Exception exc){
    if(!EventLog.SourceExists("MySource"))
    {
        EventLog.CreateEventSource("MySource", "MyNewLog");
        return ;
    }
    EventLog.WriteEntry(
     "MySource", 
     exc.ToString(), 
     EventLogEntryType.Error, 
     100); }  
0

:

Windows 7 Win 2008 R2 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\CustomEventLog - .

When trying to write to the event log with a source that is not valid (this is not a key under HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ services \ eventlog \ CustomEventLog), it lists other event logs to find out if the source exists there.

I added all the missing sources to HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ services \ eventlog \ CustomEventLog. Just create a copy of the existing keys under this key and rename it to your EventSource.

0
source

Source: https://habr.com/ru/post/1739656/


All Articles