473,395 Members | 1,377 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,395 software developers and data experts.

How to add a custom event source in C# / .NET

I've been having a problem writing to an event to the Application log. I
believe the issue is caused by the fact that the source was previously both a
custom log and the source.

I deleted the log using EventLog.Delete(logname);
I couldn't delete the source as it there was an error reporting that I
couldn't delete the event source as it had the same name as the log. Once I
deleted the log, the source appeared to not have any reference to it.

On my XP machine, I can successfully add events to the Application Log with
the same source as before. However, on a 2003 server in which I had done the
same, I cannot add that source to the Application. I can make up any other
custom source and successfully create en event in the Application log.

Code I used to create custom event:

String sourceName = "My Custom Source";
String logName = "Application";
String sEvent = "Sample Event";

EventLog log;

if (EventSourceTextBox.Text.Trim() != "")
{
if (!EventLog.SourceExists(sourceName))
EventLog.CreateEventSource(sourceName, logName);

log = new EventLog();
log.Source = sourceName;

log.WriteEntry(sEvent, EventLogEntryType.Error);
}

Does anyone have any suggestions? Thanks for any ideas.

Oct 27 '06 #1
2 3718

As a guess, make sure you have permissions.
Creating a new SourceName or LogName takes specific permissions.

Make sure you know which WindowsIdentity you're running under.
"T McDonald" <TM*******@discussions.microsoft.comwrote in message
news:F3**********************************@microsof t.com...
I've been having a problem writing to an event to the Application log. I
believe the issue is caused by the fact that the source was previously
both a
custom log and the source.

I deleted the log using EventLog.Delete(logname);
I couldn't delete the source as it there was an error reporting that I
couldn't delete the event source as it had the same name as the log. Once
I
deleted the log, the source appeared to not have any reference to it.

On my XP machine, I can successfully add events to the Application Log
with
the same source as before. However, on a 2003 server in which I had done
the
same, I cannot add that source to the Application. I can make up any other
custom source and successfully create en event in the Application log.

Code I used to create custom event:

String sourceName = "My Custom Source";
String logName = "Application";
String sEvent = "Sample Event";

EventLog log;

if (EventSourceTextBox.Text.Trim() != "")
{
if (!EventLog.SourceExists(sourceName))
EventLog.CreateEventSource(sourceName, logName);

log = new EventLog();
log.Source = sourceName;

log.WriteEntry(sEvent, EventLogEntryType.Error);
}

Does anyone have any suggestions? Thanks for any ideas.

Oct 27 '06 #2
Sorry, I should have been more clear in my original post. It is not a
permissions issue, as I can create sources and logs on the server. All the
sources I refer to other than the custom one I had referrenced before I can
apply to the Application Log. At worst, I will just choose a different source
name, but that isn't ideally what I want to do.

"sloan" wrote:
>
As a guess, make sure you have permissions.
Creating a new SourceName or LogName takes specific permissions.

Make sure you know which WindowsIdentity you're running under.
"T McDonald" <TM*******@discussions.microsoft.comwrote in message
news:F3**********************************@microsof t.com...
I've been having a problem writing to an event to the Application log. I
believe the issue is caused by the fact that the source was previously
both a
custom log and the source.

I deleted the log using EventLog.Delete(logname);
I couldn't delete the source as it there was an error reporting that I
couldn't delete the event source as it had the same name as the log. Once
I
deleted the log, the source appeared to not have any reference to it.

On my XP machine, I can successfully add events to the Application Log
with
the same source as before. However, on a 2003 server in which I had done
the
same, I cannot add that source to the Application. I can make up any other
custom source and successfully create en event in the Application log.

Code I used to create custom event:

String sourceName = "My Custom Source";
String logName = "Application";
String sEvent = "Sample Event";

EventLog log;

if (EventSourceTextBox.Text.Trim() != "")
{
if (!EventLog.SourceExists(sourceName))
EventLog.CreateEventSource(sourceName, logName);

log = new EventLog();
log.Source = sourceName;

log.WriteEntry(sEvent, EventLogEntryType.Error);
}

Does anyone have any suggestions? Thanks for any ideas.


Oct 27 '06 #3

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

Similar topics

2
by: P | last post by:
Hello, I need to use events in MIDP2.0, where EventObject class does not exist. I have built a custom event WITHOUT using EventObject (see code below: //Initially //Final) and, apparently, it has...
1
by: Victor | last post by:
I am developing a windows service application that uses a custom event. the problem is that the service installer associates the service with application log during the installation process....
0
by: Tim Reynolds | last post by:
I am using EIF to write event log entries to my application. By first creating my Event Source and then raising my event via the Event Source, I do see my entries in the Application Event Log. I...
2
by: PCC | last post by:
I am using Windows Server 2003 Enterprise Edition. I have a series of custom event log files that were created by an application gone bad. They are all showing up in the event viewer and I am not...
1
by: Simon Johnson | last post by:
I'm having trouble creating a custom event log. Here's my Code: static void Main(string args) { if (!EventLog.SourceExists("OnlineTonnages")) EventLog.CreateEventSource("OnlineTonnages","EWC...
3
by: Kevin C | last post by:
Is there a safe Application log event source? By safe, I mean one that will always exist (excluding any manual deletion) on any and all normal xp, 2003 installations. I thought "Application" was...
1
by: brad.serbus | last post by:
I am trying to figure out a way to have health monitoring throw different Event IDs into the event log, and am having a hard time. None of the customization that I have looked through so far has...
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...
6
by: tshad | last post by:
I was looking at a page that showed how to set up a custom event and it seems to work ok. But I am not sure how I would use it. How would I subscribe to it. There is actual action (such as...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.