views:

33

answers:

1

Hello, In C# VS2008 I have a service which can run from command line and as registered service. I am trying to debug my Service process I wondered why it does not write logs in event viewer. I have a logger as this:

public static void Log(string s, EventLogEntryType et) {
        try {
            if (CService.asService) {
                if (!EventLog.SourceExists("Jobs")) {
                    EventLog.CreateEventSource("Jobs", "JobsServiceLog");
                }
                EventLog.WriteEntry("Jobs", s,
                    et, 234);
            }
            else {
                Console.WriteLine(s);
            }
        }
        catch { }
    }

Then somewhere I am logging: Log("Jobs service started", EventLogEntryType.Information);

Nothing is appear in the Event Viewer->JobsServiceLog.

What can be reason?

thanks

Arman.

A: 

What's up with CService.asService? are you sure the source gets created?

sebastian
@sebastian: CService.asService=true; and service is started I can connect it by client.
Arman
i believe your problem is with the creation of the EventSource
sebastian
@sebastian: Do you mean EventLog.CreateEventSource?
Arman
yes, I believe the event source is not being created, thus, you don't see the entry on the Event Viewer
sebastian