473,499 Members | 1,589 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Wrtite Mesasges to Windows Event Viwer

Hi,
I would like to be able from my C# .NET application to send
(programatically) different debug messages to an own directory in the
standard Windows Event Viewer. Which .NET classes provide access to the
Windows Event Viewer ? Is it possible to configure it to automatically
log the messages into files after a given amount of records ? Is it
possible to have the message time-stamps in milliseconds ?
Some code sample of using such .NET classes would be appreciated.
Thanks in advance for your help.
Regards,
Abra

*** Sent via Developersdex http://www.developersdex.com ***
Nov 23 '05 #1
2 3496
private System.Diagnostics.EventLog Log;

private bool EventLoggerIsOk;

public void Initialize()

{

try

{

Log = new EventLog();

if (!EventLog.SourceExists("Source"))

{

EventLog.CreateEventSource("Source", "LogName");

}

Log.Source = "Source";

Log.Log = "LogName";

Log.ModifyOverflowPolicy(OverflowAction.OverwriteA sNeeded, 5);

EventLoggerIsOk = true;

}

catch

{

EventLoggerIsOk = false;

}

}

public System.Diagnostics.EventLogEntryCollection Events

{

get

{

return (Log.Entries);

}

}

private string PrepareMessage(string Message)

{

// Do what ever string function

return (Message);

}

public void LogMessage(string Message)

{

if (EventLoggerIsOk)

{

this.Log.WriteEntry(PrepareMessage(Message),
System.Diagnostics.EventLogEntryType.Information);

}

}

public void LogError(string Message)

{

if (EventLoggerIsOk)

{

this.Log.WriteEntry(PrepareMessage(Message),
System.Diagnostics.EventLogEntryType.Error);

}

}

public void LogWarning(string Message)

{

if (EventLoggerIsOk)

{

this.Log.WriteEntry(PrepareMessage(Message),
System.Diagnostics.EventLogEntryType.Warning);

}

}

"Abra" <no****@devdex.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Hi,
I would like to be able from my C# .NET application to send
(programatically) different debug messages to an own directory in the
standard Windows Event Viewer. Which .NET classes provide access to the
Windows Event Viewer ? Is it possible to configure it to automatically
log the messages into files after a given amount of records ? Is it
possible to have the message time-stamps in milliseconds ?
Some code sample of using such .NET classes would be appreciated.
Thanks in advance for your help.
Regards,
Abra

*** Sent via Developersdex http://www.developersdex.com ***

Nov 23 '05 #2
Thank you for the code sample, it works fine.
Is it is possible to set manually the time displayed for a message in
EventViewer, by setting it when adding a new entry ? Is it possible to
get the message time-stamp in milliseconds ?
Is there any workaround for the "ModifyOverflowPolicy" method in .NET
1.1, as it is implemented only in .NET 2.0 ?
Thanks in advance for your help.
*** Sent via Developersdex http://www.developersdex.com ***
Nov 28 '05 #3

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

Similar topics

5
2180
by: joseph | last post by:
Hi, I would like to run a windows application without the user interface. Console application is not a choice because it does not allow to use ADO controls. When I start the Windows Application I...
2
13484
by: FrodoBaggins | last post by:
Dear Team, I am running Visual Studio 2003 Version 7.1.3088 on Windows Server 2003. I have written a C# application that must write to the event log. When it attempts to write to the event log,...
8
3734
by: Ron Holmes | last post by:
I want to place a background image on a windows form. Is there a way to prevent the image from Tiling without using an image box resized to the size of the form? I am using Visual Studio 2003...
5
73175
by: RAJ | last post by:
hi plz tell me how to know "how window is going to close"... i have to right code for X button of forms... plz telll me thanks bye
8
4159
by: Bill Sonia | last post by:
I've written a Windows Service to send e-mails on events like OnStart, OnStop, OnShutDown using System.Web.Mail. It works for everything but OnShutdown. My guess is that for OnShutDown, once my...
5
11340
by: Dave | last post by:
How do I check in a Windows Forms app if any controls have changed? I have a form that collects data, and I want to prompt the user if they try to exit the app, or load a new file, without saving...
7
1898
by: MounilK | last post by:
Hi all, I am not sure if this is the right NG to post this question. If that's the case please point me to the correct NG. I have a class library(myLib.dll) which has a class(myClass) which has...
3
4662
by: bsturg21 | last post by:
Hello, I have a windows form that has a series of linklabels on it, and I need to have each linklabel, when clicked, open a separate windows form that has a single paramter passed into it. The...
5
4272
by: Klaudiusz Bryja | last post by:
Hi, This is for NetCF 2.0. I need to create event handling code which using reflection. I have some parameters in XML which describe how event should be handled. I have code to create...
0
7009
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
7178
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
7223
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...
1
6899
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
7390
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5475
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,...
1
4919
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
1427
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 ...
0
302
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.