I have an intermittent problem with some code that writes to the Windows event log using the C # and .Net EventLog classes.
Basically, this code works fine every day, but very rarely do we start to get errors like this:
"System.ArgumentException: only the first eight characters of the user log name are significant, and there is already another log in the system using the first eight characters the name is specified. Name given:" Application ", name of the existing log:" Application ".
I can determine from other information in our logs that the affected call column looks like this: you can clearly see what I'm actually trying to write to the existing LB_Email ( LogEmail is called LogEmail ):
public static void LogEmail(string to, string type) { string message = String.Format("{0}\t{1}\t{2}", DateTime.Now, to, type); Log(message, "LB_Email", EventLogEntryType.Information); } private static void Log(string message, string logName, EventLogEntryType type) { using (EventLog aLog = new EventLog()) { aLog.Source = logName; aLog.WriteEntry(message, type); } }
As soon as the errors start, it seems that access to our LB_Email event LB_Email blocked in some way - viewing the properties in a particular event log shows most of the information greyed-out and unchangeable, and other processes do not seem to be able to enter this log too . However, I see an error (which uses the same Log method above) with a try-catch that is logged in the "LB_Error" log and continues to function properly.
I am calling this code from a multi-threaded application, but I have not been able to determine whether this code is thread safe or not.
I can also confirm that the journal issue is working fine again after killing and restarting the process ... and it had the appropriate settings to reuse the entries when it was full ... although I don't think that was the problem.
I would like to hear your thoughts and suggestions.