Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 83119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:43:25+00:00 2026-05-10T21:43:25+00:00

I have an intermittent problem with some code that writes to a Windows Event

  • 0

I have an intermittent problem with some code that writes to a Windows Event Log, using C# and .Net’s EventLog class.

Basically, this code works day-to-day perfectly, but very occasionally, we start getting errors like this:

‘System.ArgumentException: Only the first eight characters of a custom log name are significant, and there is already another log on the system using the first eight characters of the name given. Name given: ‘Application’, name of existing log: ‘Application’.’

I can identify from the other information on our logs that the call stack affected is like this – You can clearly see I am in fact trying to write to an existing LB_Email log (LogEmail is called first):

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

Once the errors start occurring, it seems like access to our LB_Email eventlog is locked somehow – viewing properties on the particular eventlog shows most information greyed-out and unchangeable, and other processes appear to be prevented from logging to that log too. However, I am seeing the error (which uses the same Log method above) via a try-catch that logs to an ‘LB_Error’ log, and that continues to function as expected.

I am calling this code from a multi-threaded application, but I have been unable to identify if the code above is thread-safe or not.

I can also confirm that the log in question is working again fine after killing and restarting the process… and it had appropriate settings to reuse entries when it got full… though I don’t think that was the issue.

I’d love to hear your thoughts and suggestions.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T21:43:26+00:00Added an answer on May 10, 2026 at 9:43 pm

    The documentation states that:

    You can only use the Source to write to one log at a time

    So I suspect this problem is caused by your multithreaded app calling the Log method more that once at a given time and for the same Source.

    I suggest that, instead of a static class (or methods), you use a thread-safe singleton class for logging these events.

    EDIT:

    Jon Skeet has an excellent article on singletons.

    If you don’t want to implement a singleton class you can do something like this:

        static readonly object lockObj = new object();      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)     {         lock (lockObj)         {             using (EventLog aLog = new EventLog())             {                 aLog.Source = logName;                 aLog.WriteEntry(message, type);             }         }     } 

    Hope this solves your problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 122k
  • Answers 122k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer In the debugger, one can edit whatever is loaded in… May 12, 2026 at 12:48 am
  • Editorial Team
    Editorial Team added an answer Let's look at the classic add-n closure from What is… May 12, 2026 at 12:48 am
  • Editorial Team
    Editorial Team added an answer Use getBounds(). From the doc: Returns the the visible rectangular… May 12, 2026 at 12:48 am

Related Questions

We have some client code which is using the SqlConnection class in .NET to
I have a view containing a UIWebView which is loading a google map (so
We have a setup where we have multiple instances of an application - one
I am working on an application in Delphi 2009 which makes heavy use of

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.