473,508 Members | 2,298 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Creating Custom EventLogs

3 New Member
I am trying to write to a custom event log:
Expand|Select|Wrap|Line Numbers
  1.  
  2. if (!EventLog.SourceExists("MySource")
  3. EventLog.CreateEventSource("MySource", "MyLog");
  4.  
  5. EventLog myLog = new EventLlog();
  6. myLog.Source = "MySource";
  7. myLog.WriteEntry("Writing to MySource");
  8.  
  9.  
EventLog.SourceExists thinks "MySource" exists; however,
when I call 'WriteEntry', nothing gets created; f I try to delete it with EventLog.Delete("MySource") or ("MyLog"), ad InvalidOperationException is raised, as it thinks the log doesn't exist.

Also, I added a loop to examine all the existing logs on my server:

Expand|Select|Wrap|Line Numbers
  1. EventLog[] myEventLogs;
  2. myEventLogs = EventLog.GetEventLogs(System.Environment.MachineName);
  3. for (int i = 0; i < myEventLogs.Length; i++)
  4.             Console.WriteLine(" Log: " + myEventLogs[i].Log + " \n Source: " + myEventLogs[i].Source);
  5.  
The log doesn't show up at all.

I am logged on with admin privileges.
Can someone please help out here?

Thanks
Sep 14 '10 #1
4 1238
PRR
750 Recognized Expert Contributor
I ran your code, it seems to work fine on my machine.
Expand|Select|Wrap|Line Numbers
  1. if (!EventLog.SourceExists("MySource"))
  2.             {
  3.             EventLog.CreateEventSource("MySource", "MyLog"); 
  4.             }
  5.  
  6.         EventLog myLog = new EventLog(); 
  7.         myLog.Source = "MySource"; 
  8.         myLog.WriteEntry("Writing to MySource"); 
  9.  
Create and Remove Custom Event Logs
Sep 14 '10 #2
Plater
7,872 Recognized Expert Expert
Wouldn't the myLog object need to reference the log itself?
new EventLog("MyLog", myMachineName, "MySource");
Sep 14 '10 #3
Mainframe Guy
3 New Member
That overloaded method is obsolete.
My problem is that I am not able to write to the custom event log.
I added code to display all the logs on the computer, as well as to see where (if anywhere) my intended source is registered.

Expand|Select|Wrap|Line Numbers
  1.  
  2. EventLog[] myLogs;
  3.         myLogs = EventLog.GetEventLogs(myMachine);
  4.         Console.WriteLine("Number of logs on computer: " + myLogs.Length);
  5.  
  6.         for (int i = 0; i < myLogs.Length; i++)
  7.             Console.WriteLine("Log: " + myLogs[i].Log);
  8.  
  9.         Console.WriteLine("Source " + sourceName + " is registered to " + EventLog.LogNameFromSourceName(logName, myMachine));
  10.  
  11.  
I can see that sourceName exists and is registered to logName; however, when I write to the log it always ends up in the application log, not my custom event log:

Expand|Select|Wrap|Line Numbers
  1.  
  2. if (!(EventLog.SourceExists(sourceName, System.Environment.MachineName)))
  3.             EventLog.CreateEventSource(sourceName, logName);
  4.         EventLog myLog = new EventLog(logName);
  5.         myLog.Source = sourceName;
  6.         myLog.WriteEntry(" writing to log " + logName);
  7.  
  8.  
I always see my entry with sourceName as the Source, but written to the Application log. However, the entry goes on that the description for Event ID (0) in Source ( mySource) cannot be found...

Hopefully this is just a novice error; but any help will be greatly appreciated
Sep 14 '10 #4
PRR
750 Recognized Expert Contributor
I would suggest try running your code( and some samples) on another machine. See if it works fine there. I do remeber encountering similar problem years back, of custom logs written to Application log.

Expand|Select|Wrap|Line Numbers
  1. try
  2.             {
  3.                 if (!EventLog.SourceExists("One", Environment.MachineName))
  4.                 {
  5.                     EventSourceCreationData data = new EventSourceCreationData("One", "Log1");
  6.                     data.MachineName = Environment.MachineName;
  7.  
  8.                     EventLog.CreateEventSource(data);//("One", "Log1", Environment.MachineName);
  9.                 }
  10.  
  11.                 using (EventLog e = new EventLog("Log1", Environment.MachineName, "One"))
  12.                 {
  13.  
  14.                     e.WriteEntry("hi", EventLogEntryType.Information, 666, 2);
  15.                 }
  16.             }
  17.             catch (Exception ec)
  18.             {
  19.                 Console.WriteLine(ec.Message.ToString());
  20.             }
  21.  
Sep 15 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
4603
by: Tom Alcendor | last post by:
I am building a chess game application that allows a user to click on a piece and move it to a new square. When the user clicks on a piece the mouse pointer must change to the image associated...
0
1133
by: Albinas | last post by:
Dear all, I am a beginner in VB.NET and I have just taken the course 2565. (So, you can see how fresh I am.) I am creating a custom textbox and adding some new attributes to the textbox. ...
4
6557
by: NutJob | last post by:
Hello, I'm faced with the following problem: I have a (secondary) thread that monitors a socket for incoming message traffic using the select.select() function. Besides that I also have the...
0
1607
by: Jai | last post by:
Dear All Creating Custom Controls but Not User Controls,How to create custom controls,i.e Extending the functionality of the Existing Controls.(Web Custom Controls). Previously i have...
4
2303
by: Alvo von Cossel I | last post by:
hi, i have been asked to make a good-looking app for a friend. i have an options form with a big tabstrip in it. 1. how can i customize it e.g. change from the standard system style...
3
1917
by: Kyle Fitzgerald | last post by:
I've started a web control library project and can build my own controls to add to the toolbox in the .NET environment. The problem I'm having is I want to create a control just like the HTML...
0
1432
by: Julien | last post by:
Hi ! I'm creating a custom control, in which I would render an image with client-side script code to display/hide a calendar control which also belong to my custom control. In this control I've...
0
1364
by: Nenefta | last post by:
Good afternoon everyone, I would like to create a custom GridViewand use that in the rest of my project, so all GridViews look the same. I thought it would be as easy as creating a usercontrol...
0
1151
by: Ric | last post by:
I have a mandate from a customer to create custom bubble and gannt charts that are viewable in their Web browser. We explored some of the charting tools and controls but because of the complexity...
1
2169
by: Abdo Haji-Ali | last post by:
Previously I used to create user controls if I wanted to use a specific set of controls in multiple pages, however I want to deploy my control in other applications so I thought of creating custom...
0
7225
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
7324
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,...
1
7042
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...
0
5627
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4707
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...
0
3193
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...
0
1556
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 ...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.