Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Log for EventLog Source

Tags:

c#

event-log

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.");
like image 497
Tim Avatar asked Jul 30 '26 05:07

Tim


1 Answers

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.

like image 91
Tim Avatar answered Jul 31 '26 17:07

Tim