简体   繁体   中英

Change Log for EventLog Source

Our company just changed our name, and I am rebranding some of the software. One issue I have run into is that we write to the Event log as Company Name.ProductName . Is there a way to change the Log for a Source without deleting and recreating the Source.

I have been able to determine what Log the Source is associated, but am not sure how to change the log over without deleting existing data outside of changing the Product Name which I would rather not do.

        if (!System.Diagnostics.EventLog.SourceExists("ProductName"))
        {
            System.Diagnostics.EventLog.CreateEventSource(
                "ProductName", "Company Name");
        }
        else if (!EventLog.LogNameFromSourceName("ProductName", ".").Equals("Company Name"))
        {
            // ??? Not sure what to do here ???
        }
        eventLog.Source = "ProductName";
        eventLog.Log = "Company Name";
        eventLog.WriteEntry("The Service has been created.");

It turns out that you cannot change the Log that the Source is associated with. You can delete the Source, and create a new one associated with a different log, but the computer will need to be rebooted before the change takes effect.

I decided to just change the Source name enough that it would create a new Source log under the correct Log file.

This information comes partly from here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM