473,647 Members | 3,347 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
(programaticall y) 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 3505
private System.Diagnost ics.EventLog Log;

private bool EventLoggerIsOk ;

public void Initialize()

{

try

{

Log = new EventLog();

if (!EventLog.Sour ceExists("Sourc e"))

{

EventLog.Create EventSource("So urce", "LogName");

}

Log.Source = "Source";

Log.Log = "LogName";

Log.ModifyOverf lowPolicy(Overf lowAction.Overw riteAsNeeded, 5);

EventLoggerIsOk = true;

}

catch

{

EventLoggerIsOk = false;

}

}

public System.Diagnost ics.EventLogEnt ryCollection Events

{

get

{

return (Log.Entries);

}

}

private string PrepareMessage( string Message)

{

// Do what ever string function

return (Message);

}

public void LogMessage(stri ng Message)

{

if (EventLoggerIsO k)

{

this.Log.WriteE ntry(PrepareMes sage(Message),
System.Diagnost ics.EventLogEnt ryType.Informat ion);

}

}

public void LogError(string Message)

{

if (EventLoggerIsO k)

{

this.Log.WriteE ntry(PrepareMes sage(Message),
System.Diagnost ics.EventLogEnt ryType.Error);

}

}

public void LogWarning(stri ng Message)

{

if (EventLoggerIsO k)

{

this.Log.WriteE ntry(PrepareMes sage(Message),
System.Diagnost ics.EventLogEnt ryType.Warning) ;

}

}

"Abra" <no****@devdex. com> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
Hi,
I would like to be able from my C# .NET application to send
(programaticall y) 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 "ModifyOverflow Policy" 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
2198
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 do not want to see the Form and click some buttons to start a program. The program should start executing the main program immediately. Thank you very much for help.
2
13506
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, however, I get the following message on the browser shown below in bold text: Security Exception Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required...
8
3754
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 .NET. This is an easy thing to do in VB6.
5
73202
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
4182
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 send mail code is executed, other necessary Windows Services have been terminated before it can actually send the mail. I've updated my HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services registry DependOnService value including SMPTSVC and...
5
11354
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 changes that have been made. In MFC/Win32, you'd trap the WM_COMMAND/EN_CHANGE notification messages, etc. But, this doesn't seem to happen in Windows Forms. I tried Spy-ing a windows forms app, and the WM_COMMAND messages don't even get sent...
7
1908
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 a method(myClassMethod) that creates a form with a button on it. The application that calls the dll is a windows application(myWinApp). When in myWinApp I do, myClass.myClassMethod, a form is created.
3
4680
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 form that has the System.Windows.Forms.LinkLabel controls on it is in a different project and under a different namespace from the file where the LinkLabel_LinkClicked events are, so I can't just do frm.ShowDialog under the LinkClicked method. ...
5
4289
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 delegate: public class DelegateEx {
0
8275
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
8715
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...
0
8645
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8371
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
7209
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5580
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
4095
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
4209
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1516
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.