473,788 Members | 2,807 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 = "Applicatio n";
String sEvent = "Sample Event";

EventLog log;

if (EventSourceTex tBox.Text.Trim( ) != "")
{
if (!EventLog.Sour ceExists(source Name))
EventLog.Create EventSource(sou rceName, logName);

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

log.WriteEntry( sEvent, EventLogEntryTy pe.Error);
}

Does anyone have any suggestions? Thanks for any ideas.

Oct 27 '06 #1
2 3742

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*******@disc ussions.microso ft.comwrote in message
news:F3******** *************** ***********@mic rosoft.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 = "Applicatio n";
String sEvent = "Sample Event";

EventLog log;

if (EventSourceTex tBox.Text.Trim( ) != "")
{
if (!EventLog.Sour ceExists(source Name))
EventLog.Create EventSource(sou rceName, logName);

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

log.WriteEntry( sEvent, EventLogEntryTy pe.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*******@disc ussions.microso ft.comwrote in message
news:F3******** *************** ***********@mic rosoft.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 = "Applicatio n";
String sEvent = "Sample Event";

EventLog log;

if (EventSourceTex tBox.Text.Trim( ) != "")
{
if (!EventLog.Sour ceExists(source Name))
EventLog.Create EventSource(sou rceName, logName);

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

log.WriteEntry( sEvent, EventLogEntryTy pe.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
4065
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 the same behaviour as the same one extending this class. My question is: Is it possible to build a custom event without extending EventObject that has the same behaviour as one which extends class EventObject? What am I missing? //public class...
1
1388
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. Therefore, the custom log does not recieve messages from the event source. Below is code snipet ' check if log exists on this machine If Not EventLog.SourceExists("trkProcessMin") Then
0
1241
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 want to create a custom Event log and have my log messages go there instead of to the Application Log. If not using EIF, I know I could do it using System.Diagnostics.EventLog.CreateEventSource ("Source1", "CustomLog");
2
4595
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 sure how to get rid of them. Any advice, links or pointers? Please keep in mind that these are NOT the system event log files. Thank you.
1
5439
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 Applications",Environment.MachineName);
3
1318
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 one but apparently its not. Kevin
1
3006
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 been helpful, yet. As an example, here's a text copy of a typical unhandled exception from the event log: Event Type: Warning Event Source: ASP.NET 2.0.50727.0
0
894
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 source is empty. It should have displayed MyTest because that is my source. It looks like this Typ Datum Tid Källa ... Information 2007-10-30 16:16:53
6
1885
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 pressing a button or changing text in a textbox). It gets set up and on the user control on my web page I can see the event from intellisense. So it seems to be set up, but I am trying to get an easy example of how I would now use this event. ...
0
9656
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10373
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10118
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5403
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5538
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4074
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.