EventLog.SourceExists question....

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to write to the EventLog from a WindowsService that I have written,
however when I check to see if the Event Log exists (which it does) it fails.

Here's the code.

if (EventLog.SourceExists(this.szLogName.ToString()) == false)

Here are all the iterations of the above that do not work:
if (!EventLog.SourceExists(this.szLogName))
if (EventLog.SourceExists(this.szLogName) == false)

It will work if I explicitly use the string value of this.szLogName, but it
is not my
prefered method.

Any thoughts?
 
I am trying to write to the EventLog from a WindowsService that I have written,
however when I check to see if the Event Log exists (which it does) it fails.

Here's the code.

if (EventLog.SourceExists(this.szLogName.ToString()) == false)

Here are all the iterations of the above that do not work:
if (!EventLog.SourceExists(this.szLogName))
if (EventLog.SourceExists(this.szLogName) == false)

It will work if I explicitly use the string value of this.szLogName, but it
is not my
prefered method.

So what you mean is that if you execute:
if (!EventLog.SourceExists("YourEventSourceName"))
it works while if you execute
if (!EventLog.SourceExists(this.szLogName))
it fails?

Looks like this.szLogName does not contain what you expect it to contain.
Are you sure that you are setting the (correct) value of szLogName? How are
you initializing it?
 
Mehdi,

I have verified that it contains what I expect it to.

I've written that value to a debug file and it is what I expect, and well as
the
errors that arise because of the value.

Any other thoughts?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top