Wild-@$$ Guess: When the app is trying to see if the event source already exists it is trying to enumerate over the set of existing sources but there some it cannot read/see. There is no good response (true or false) so the call throws. Even if you are a local admin you might need to run in Elevated Privileges to perfrom that action. Try right clicking on your console app and selecting "Run as Administrator" and see if that works.
Michael M. Minutillo Indiscriminate Information Sponge http://codermike.com On Fri, Dec 9, 2011 at 3:20 PM, Peter Maddin <[email protected]>wrote: > I wrote a simple console application to test writing to the application > event log.**** > > ** ** > > However I get an exception when I run it (Windows 7)**** > > ** ** > > What am I doing wrong?**** > > I am a local administrator and I only want to write to the existing > application event log.**** > > If I can’t get this to work, how will the average Joe User?**** > > ** ** > > using System;**** > > using System.Collections.Generic;**** > > using System.Linq;**** > > using System.Text;**** > > using System.Threading;**** > > using System.Diagnostics;**** > > **** > > namespace ConsoleEventLog**** > > {**** > > class Program**** > > {**** > > const string ConsoleEvents = "ConsoleEvents";**** > > static void Main(string[] args)**** > > {**** > > bool hadEnough = false;**** > > **** > > // Exception here**** > > > // {"The source was not found, but some or all event logs could not be > searched. Inaccessible logs: Security."} > **** > > if (!EventLog.SourceExists(ConsoleEvents))**** > > EventLog.CreateEventSource(ConsoleEvents, "Application");* > *** > > **** > > while (!hadEnough)**** > > {**** > > Console.WriteLine("1 : Error event");**** > > Console.WriteLine("2 : Warning event");**** > > Console.WriteLine("3 : Info event");**** > > Console.WriteLine("4 : Exit");**** > > Console.WriteLine("");**** > > var x = Console.ReadKey();**** > > Console.WriteLine("");**** > > switch (x.KeyChar)**** > > {**** > > case '1':**** > > Console.WriteLine("1 pressed");**** > > LogError();**** > > break;**** > > case '2':**** > > Console.WriteLine("2 pressed");**** > > LogWarning();**** > > break;**** > > case '3':**** > > Console.WriteLine("3 pressed");**** > > LogInfo();**** > > break;**** > > case '4':**** > > Console.WriteLine("4 pressed");**** > > hadEnough = true;**** > > break;**** > > default:**** > > Console.WriteLine("Don't be a cretin");**** > > break;**** > > }**** > > Thread.Sleep(1000);**** > > Console.Clear();**** > > }**** > > }**** > > **** > > public static void LogError()**** > > {**** > > EventLog.WriteEntry(ConsoleEvents, "this is an error event", > EventLogEntryType.Error, 1);**** > > }**** > > **** > > public static void LogWarning()**** > > {**** > > EventLog.WriteEntry(ConsoleEvents, "this is an warning event" > , EventLogEntryType.Warning, 2);**** > > }**** > > **** > > public static void LogInfo()**** > > {**** > > EventLog.WriteEntry(ConsoleEvents, > "this is an informational event", EventLogEntryType.Information, 3);**** > > }**** > > }**** > > }**** > > ** ** > > *Regards Peter Maddin* > *Applications Development Officer* > *Path**West Laboratory Medicine WA* > *Phone : +618 6396 4285 (Monday, Wednesday,Friday)* > > *Phone : +618 9346 4372 (Tuesday, Thursday)** > Mobile: 0423 540 825* > *E-Mail : [email protected]; [email protected]* > *The contents of this e-mail transmission outside of the WAGHS network > are intended solely for the named recipient's), may be confidential, and > may be privileged or otherwise protected from disclosure in the public > interest. The use, reproduction, disclosure or distribution of the contents > of this e-mail transmission by any person other than the named recipient(s) > is prohibited. If you are not a named recipient please notify the sender > immediately**.***** > > **** > > ** ** > > *From:* [email protected] [mailto: > [email protected]] *On Behalf Of *Joseph Clark > > *Sent:* Friday, 9 December 2011 2:02 PM > *To:* ozDotNet > *Subject:* Re: Event Log**** > > ** ** > > As far I can remember from the last time I looked at this stuff... writing > to the event log as a Joe user is fine - the problem is that creating the > "event source" for the log entries required administrative escalation. > > > **** > > On Fri, Dec 9, 2011 at 4:24 PM, Peter Maddin <[email protected]> > wrote:**** > > I am looking at maintaining an old vs2005 vb.net application.**** > > **** > > This has been running on XP Pro workstations.**** > > From trawling through the code, I have found that it uses the event log > for recording errors.**** > > **** > > I have open and converted the solution into VS2010.**** > > I noticed that errors are being written to the application event log.**** > > **** > > I suspect that on windows 7 (probably Vista as well) that a normal user > may run into problems when trying to write to the application event log.** > ** > > **** > > Is this likely to be a problem if the application is installed on windows > 7 and run by a user with minimal rights and permissions?**** > > **** > > *Regards Peter Maddin* > *Applications Development Officer* > *Path**West Laboratory Medicine WA* > *Phone : +618 6396 4285 (Monday, Wednesday,Friday)***** > > *Phone : +618 9346 4372 (Tuesday, Thursday) > Mobile: 0423 540 825* > *E-Mail : [email protected]; [email protected]* > *The contents of this e-mail transmission outside of the WAGHS network > are intended solely for the named recipient's), may be confidential, and > may be privileged or otherwise protected from disclosure in the public > interest. The use, reproduction, disclosure or distribution of the contents > of this e-mail transmission by any person other than the named recipient(s) > is prohibited. If you are not a named recipient please notify the sender > immediately**.***** > > **** > > **** > > ** ** >
