How To Write Error In Event Log C#
Contents |
360 games PC games c# write to application event log Windows games Windows phone games Entertainment All Entertainment
C# Write To Event Log Without Admin
Movies & TV Music Business & Education Business Students & educators c# write exception to event log Developers Sale Sale Find a store Gift cards Products Software & services Windows Office Free downloads & security Internet
Eventlog Class
Explorer Microsoft Edge Skype OneNote OneDrive Microsoft Health MSN Bing Microsoft Groove Microsoft Movies & TV Devices & Xbox All Microsoft devices Microsoft Surface All Windows PCs & tablets PC accessories Xbox & games Microsoft Lumia All c# create event log Windows phones Microsoft HoloLens For business Cloud Platform Microsoft Azure Microsoft Dynamics Windows for business Office for business Skype for business Surface for business Enterprise solutions Small business solutions Find a solutions provider Volume Licensing For developers & IT pros Develop Windows apps Microsoft Azure MSDN TechNet Visual Studio For students & educators Office for students OneNote in classroom Shop PCs & tablets perfect for students Microsoft in Education Support Sign in Cart Cart Javascript is disabled Please enable javascript and refresh the page Cookies are disabled Please enable cookies and refresh the page CV: {{ getCv() }} English (United States) Terms of use Privacy & cookies Trademarks © 2016 Microsoft
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and
C# Read Windows Event Log
policies of this site About Us Learn more about Stack Overflow the
Eventlog.writeentry Where To Find
company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users eventlog.writeentry not working Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes https://support.microsoft.com/en-us/kb/307024 a minute: Sign up c# writing to the event viewer up vote 50 down vote favorite 12 I'm trying to write to the event viewer in my c# code, but I'm getting the wonderful "Object reference not set to an instance of an object" message. I'd appreciate some help with this code, either what's wrong with it or even a better way http://stackoverflow.com/questions/1133355/c-sharp-writing-to-the-event-viewer to do it. Here's what I have for writing to the event log: private void WriteToEventLog(string message) { string cs = "QualityDocHandler"; EventLog elog = new EventLog(); if (!EventLog.SourceExists(cs)) { EventLog.CreateEventSource(cs, cs); } elog.Source = cs; elog.EnableRaisingEvents = true; elog.WriteEntry(message); } And here's where I'm trying to call it: private readonly Random _rng = new Random(); private const string _chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; private string RandomString(int size) { try { char[] buffer = new char[size]; for (int i = 0; i < size; i++) { buffer[i] = _chars[_rng.Next(_chars.Length)]; } return new string(buffer); } catch (Exception e) { WriteToEventLog(e.ToString()); return null; } } c# event-log share|improve this question asked Jul 15 '09 at 19:12 PushCode 1,42941726 what line is the error on? –NikolaiDante Jul 15 '09 at 19:13 please provide a stack trace –Brad Barker Jul 15 '09 at 19:16 "Object reference not set to an instance of an object" - means that you are referencing a NULL, it is much more helpful to know the line of code where this happens, because then you can see what
here for a quick overview of the site Help Center Detailed answers to any questions you might http://stackoverflow.com/questions/1184059/writing-exceptions-to-the-windows-log-file have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, event log just like you, helping each other. Join them; it only takes a minute: Sign up Writing Exceptions to the Windows Log File up vote 28 down vote favorite 4 I'd like to catch my exceptions and log them in the Windows log file. How do I go about opening and writing to the Windows log? c# write to c# windows logging event-log share|improve this question edited Sep 17 '09 at 14:06 Even Mien 15.1k3192109 asked Jul 26 '09 at 8:47 Gold 15k76173276 add a comment| 5 Answers 5 active oldest votes up vote 25 down vote accepted You can use the System.Diagnostics.EventLog.WriteEntry function to write entries to the event log. System.Diagnostics.EventLog.WriteEntry("MyEventSource", exception.StackTrace, System.Diagnostics.EventLogEntryType.Warning); To read event logs you can use the System.Diagnostics.EventLog.GetEventLogs function. //here's how you get the event logs var eventLogs = System.Diagnostics.EventLog.GetEventLogs(); foreach(var eventLog in eventLogs) { //here's how you get the event log entries foreach(var logEntry in eventLog.Entries) { //do something with the entry } } share|improve this answer answered Jul 26 '09 at 9:02 Doctor Jones 14.7k105185 add a comment| up vote 10 down vote You can also consider using the Enterprise Library. It looks complicated to start with but an hour or two of playing will pay off. Config is stored in app.config so you can change it without recompiling - this can be really handy when you