473,383 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

EventLog.SourceExists question....

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?
Apr 24 '07 #1
2 2825
On Tue, 24 Apr 2007 08:08:05 -0700, Joe wrote:
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?
Apr 24 '07 #2
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?
On Tue, 24 Apr 2007 08:08:05 -0700, Joe wrote:
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?
Apr 24 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: José Joye | last post by:
I know, this kind of question has already been asked. However, I could not find an answer related to the minimal privilege required to be able to create a new event Source in the appplication event...
4
by: Steven | last post by:
I just downloaded the June 2005 release and I want to set up basic logging to log problems such as exceptions. I have created a category named Exceptions with the following: <category...
2
by: Next | last post by:
Hello all, I have a windows service that was suppose to write some events into its own EventLog. I created the EventLog using the component on VS 2003 toolbar Added an installer for it. Set...
1
by: martin | last post by:
Hi, I'm having some problems with the System.Diagnostics.EventLog class in .NET 2.0 I need to recreate an event message source inside a new log but the messages keeps ending up in the old...
0
by: rene | last post by:
I'm trying to use costome categories in my eventlog for a program I'm writing. But I have some problems with it, I cant get it to work. Checklist for how I did this. 1. Created a...
0
by: Taps | last post by:
In the EventLog.Delete method, after you delete a log, it says that you can recreate the log, but then you cannot re-register the logsources (you had earlier created) (refer to the below notes)....
0
by: TonyJ | last post by:
Hello! Below is a snippet which doesn't work as expected. Here I create a custom event log named MyLog and a source named MyTest but when I look at the MyLog the column which should display the...
2
by: Dennis | last post by:
I have a service with the following startup code... When I start the service I see a new entry under... Computer Management(local) System Tools Event Viewer Application MyServiceLog ...
1
by: Jeff | last post by:
hi ..Net 2.0 I've created the code below and think I've executed it. After I thought I've executed it I checked in EventLog on the computer (win2k3) and no entry was added. This could mean 2...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.