Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am creating a new event source and logging a message using the code below:

    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);
    }

A custom event log with the name "My Log" is created (as expected) but the message is logged below the "Application" node. What am I doing wrong?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
319 views
Welcome To Ask or Share your Answers For Others

1 Answer

There's the following note in 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.

Is it possible while trying out the code that you previously tried writing to the Application log and you now need to reboot for it to "unmap" that link?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...