A question on having multiple source log to an eventlog
-
I have a service that launches multiple threads. Each thread has a unique purpose and thus they are unique sources. I have a successfully created log file named OneSource and I want all of the sources logging events to that log file. Currently I have each thread initializing and accessing the EventLog with their own instances, the service itself does not do any logging. My first thread that I start successfully initialized and logs to the file but subsequent ones do not. Here is my eventlog initialization logic (some names were changed to protect the innocent :) :
#region Eventlog initialization bool creationNeeded = false; if ( !EventLog.SourceExists( "someSource" ) ) creationNeeded = true; else if ( !EventLog.LogNameFromSourceName( "someSource", "." ).Equals( "OneSource" ) ) { creationNeeded = true; // management changed the log name again! EventLog.DeleteEventSource( "someSource" ); } if ( creationNeeded ) { EventLog.CreateEventSource( "someSource", "OneSource" ); } events = new System.Diagnostics.EventLog( "OneSource", ".", "someSource" ); events.WriteEntry( "someSource: Event log successfully started.", EventLogEntryType.Information ); #endregion
FYI: We had management constantly changing their minds on the log file to use so we had to add code to make sure that the old log was deleted before we used the new logfile name and source. I see the initialization message from sourceOne, but not from sourceTwo or sourceThree. Nor do I see any logged messages from anything but sourceOne. Also...I see Information logged entries from sourceOne, but I never see anything logged where I use an AuditSuccess state for the log event. Any guidance would be appreciated.
-
I have a service that launches multiple threads. Each thread has a unique purpose and thus they are unique sources. I have a successfully created log file named OneSource and I want all of the sources logging events to that log file. Currently I have each thread initializing and accessing the EventLog with their own instances, the service itself does not do any logging. My first thread that I start successfully initialized and logs to the file but subsequent ones do not. Here is my eventlog initialization logic (some names were changed to protect the innocent :) :
#region Eventlog initialization bool creationNeeded = false; if ( !EventLog.SourceExists( "someSource" ) ) creationNeeded = true; else if ( !EventLog.LogNameFromSourceName( "someSource", "." ).Equals( "OneSource" ) ) { creationNeeded = true; // management changed the log name again! EventLog.DeleteEventSource( "someSource" ); } if ( creationNeeded ) { EventLog.CreateEventSource( "someSource", "OneSource" ); } events = new System.Diagnostics.EventLog( "OneSource", ".", "someSource" ); events.WriteEntry( "someSource: Event log successfully started.", EventLogEntryType.Information ); #endregion
FYI: We had management constantly changing their minds on the log file to use so we had to add code to make sure that the old log was deleted before we used the new logfile name and source. I see the initialization message from sourceOne, but not from sourceTwo or sourceThree. Nor do I see any logged messages from anything but sourceOne. Also...I see Information logged entries from sourceOne, but I never see anything logged where I use an AuditSuccess state for the log event. Any guidance would be appreciated.
Wow, is that production code with all those string literals? Are you kidding me?
LongRange.Shooter wrote:
I see the initialization message from sourceOne, but not from sourceTwo or sourceThree.
Well I don't see any string literals for anything but
someSource
andOneSource
in the code you posted so based on that seeing anything else is just not possible, period. ASIDE: The code you posted is horrible, literally.led mike
-
Wow, is that production code with all those string literals? Are you kidding me?
LongRange.Shooter wrote:
I see the initialization message from sourceOne, but not from sourceTwo or sourceThree.
Well I don't see any string literals for anything but
someSource
andOneSource
in the code you posted so based on that seeing anything else is just not possible, period. ASIDE: The code you posted is horrible, literally.led mike
Well, smartass, you don't see it because it is just the initialization code for someSource. The other initialization routines are the same, but someSource is replace with anotherSource, finalSource (for example). It is representative code of the initialization routine. And, BTW, in a recent technology testing I took I rated in the top 5% internationally as a C# coder. So do you have anything helpful to add or do you just like hearing yourself blow crap out your mouth?
-
Well, smartass, you don't see it because it is just the initialization code for someSource. The other initialization routines are the same, but someSource is replace with anotherSource, finalSource (for example). It is representative code of the initialization routine. And, BTW, in a recent technology testing I took I rated in the top 5% internationally as a C# coder. So do you have anything helpful to add or do you just like hearing yourself blow crap out your mouth?
-
Well, smartass, you don't see it because it is just the initialization code for someSource. The other initialization routines are the same, but someSource is replace with anotherSource, finalSource (for example). It is representative code of the initialization routine. And, BTW, in a recent technology testing I took I rated in the top 5% internationally as a C# coder. So do you have anything helpful to add or do you just like hearing yourself blow crap out your mouth?
-
Well, smartass, you don't see it because it is just the initialization code for someSource. The other initialization routines are the same, but someSource is replace with anotherSource, finalSource (for example). It is representative code of the initialization routine. And, BTW, in a recent technology testing I took I rated in the top 5% internationally as a C# coder. So do you have anything helpful to add or do you just like hearing yourself blow crap out your mouth?
Let me get this staight...someone who is a site MVP and appears to be much more experienced than you told you that your code was not good. Yeah, he could have said it better, but calling him names is going to get you ignored permanently.
LongRange.Shooter wrote:
in a recent technology testing I took I rated in the top 5% internationally as a C# coder.
Don't make claims like this unless you can prove it.
CP Offenders: Over 50 offenders and growing! Current rant: "Me thinks CP needs an application process!" http://craptasticnation.blogspot.com/[^]
-
LongRange.Shooter wrote:
in a recent technology testing I took I rated in the top 5% internationally as a C# coder.
So was it an easy test then? ;)
Bob Ashfield Consultants Ltd
No it was the Robert Half test, locally most got only 75% and internationally the average was 79% while I scored 92%.
-
Let me get this staight...someone who is a site MVP and appears to be much more experienced than you told you that your code was not good. Yeah, he could have said it better, but calling him names is going to get you ignored permanently.
LongRange.Shooter wrote:
in a recent technology testing I took I rated in the top 5% internationally as a C# coder.
Don't make claims like this unless you can prove it.
CP Offenders: Over 50 offenders and growing! Current rant: "Me thinks CP needs an application process!" http://craptasticnation.blogspot.com/[^]
Well, first of all I don't care who or what he is. He could answer the question or shut up. He did not answer the question nor did he behave in a fashion I'd expect of a site MVP. Secondly, his comment was one of a smartass not someone being helpful. Finally, my claim can be backed up by anyone that has access to the Robert Half testing scores...the results showed that locally here the average score was 72 and internationally it was 79 while I score 93. As to more experience....I've not seen anything that indicates he has more experience than me, especially since I've been writing code for 30 years and he's only been at it 15 years. I was also in a group that was part of the C# early adapters program and was working with Microsoft in finalizing the language within Visual Studio. Being a site MVP just means he either has no job or no life so he can jump in and answer a ton of questions before anyone else. I've been on this site for many years, been help to many people and I always try to provide help and not criticism, except where some constructive criticism can be of help. Finally with the exception of the use of the various literals in beta code, there is nothing wrong with my code that I can see. And if there was indeed a major issue with how I wrote the code I'd love to have some one point out what it is.
-
I have a service that launches multiple threads. Each thread has a unique purpose and thus they are unique sources. I have a successfully created log file named OneSource and I want all of the sources logging events to that log file. Currently I have each thread initializing and accessing the EventLog with their own instances, the service itself does not do any logging. My first thread that I start successfully initialized and logs to the file but subsequent ones do not. Here is my eventlog initialization logic (some names were changed to protect the innocent :) :
#region Eventlog initialization bool creationNeeded = false; if ( !EventLog.SourceExists( "someSource" ) ) creationNeeded = true; else if ( !EventLog.LogNameFromSourceName( "someSource", "." ).Equals( "OneSource" ) ) { creationNeeded = true; // management changed the log name again! EventLog.DeleteEventSource( "someSource" ); } if ( creationNeeded ) { EventLog.CreateEventSource( "someSource", "OneSource" ); } events = new System.Diagnostics.EventLog( "OneSource", ".", "someSource" ); events.WriteEntry( "someSource: Event log successfully started.", EventLogEntryType.Information ); #endregion
FYI: We had management constantly changing their minds on the log file to use so we had to add code to make sure that the old log was deleted before we used the new logfile name and source. I see the initialization message from sourceOne, but not from sourceTwo or sourceThree. Nor do I see any logged messages from anything but sourceOne. Also...I see Information logged entries from sourceOne, but I never see anything logged where I use an AuditSuccess state for the log event. Any guidance would be appreciated.
LongRange.Shooter wrote:
I have a service that launches multiple threads. Each thread has a unique purpose and thus they are unique sources. I have a successfully created log file named OneSource and I want all of the sources logging events to that log file.
A possibility exists: Is this service running under the LocalSystem account?? If so, it doesn't have the permissions to execute the
EventLog.SourceExists
method and will throw a SecurityException. Sources should be created by the service installer, not the service itself.A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
LongRange.Shooter wrote:
I have a service that launches multiple threads. Each thread has a unique purpose and thus they are unique sources. I have a successfully created log file named OneSource and I want all of the sources logging events to that log file.
A possibility exists: Is this service running under the LocalSystem account?? If so, it doesn't have the permissions to execute the
EventLog.SourceExists
method and will throw a SecurityException. Sources should be created by the service installer, not the service itself.A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008Hi Dave. I'm not getting any exceptions during the process execution. But I am running under LocalSystem. I have security set to LinkDemand inheriting the rights from the service, and the service (for now) Asserts SecurityPermission. We are still in development and (as pointed out) we have a constantly changing environment at the moment. In fact we may be looking at yet another log file change in a few months just because the owning company is going to change the company name and they don't want a log file with the old name. Thanks.
-
Hi Dave. I'm not getting any exceptions during the process execution. But I am running under LocalSystem. I have security set to LinkDemand inheriting the rights from the service, and the service (for now) Asserts SecurityPermission. We are still in development and (as pointed out) we have a constantly changing environment at the moment. In fact we may be looking at yet another log file change in a few months just because the owning company is going to change the company name and they don't want a log file with the old name. Thanks.
LongRange.Shooter wrote:
I'm not getting any exceptions during the process execution.
Since it's a service that runs under a different desktop you won't see any exceptions. The reason it will fail is because that method call digs into the registry to get the information, and the bulk of the registry is off-limits to the LocalSystem account.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
No it was the Robert Half test, locally most got only 75% and internationally the average was 79% while I scored 92%.
Oh, I see. I've looked Robert Half up now, I didn't realise they were a recruitment agency, I thought they were a just a certification company, like say CompuTeach here in the UK. Obviously their tests will carry a lot of weight in the development community :-D ;)
Bob Ashfield Consultants Ltd