Asp.net Log Error To Event Viewer
Contents |
One games Xbox 360 games PC c# write to application event log games Windows games Windows phone games Entertainment All c# eventlog Entertainment Movies & TV Music Business & Education Business Students & c# write exception to event log educators Developers Sale Sale Find a store Gift cards Products Software & services Windows Office Free downloads & security c# write to event log without admin Internet 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 Band Microsoft
Eventlog Class
Lumia All 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
Written by Imar Spaanjaars Posted 04/16/2004 01:33 Modified 12/07/2006 17:25 Reviewed 12/07/2006 17:25 Page views 209045 Listened to Summer's Gone by Placebo (Track 10 from the album: http://imar.spaanjaars.com/275/logging-errors-to-the-event-log-in-aspnet-applications Without You I'm Nothing) Print this Page Looking to hire? Are you http://stackoverflow.com/questions/712203/writing-to-an-event-log-in-asp-net-on-windows-server-2008-iis7 looking to hire an experienced software developer or .NET consultant? Then get in touch with me through my company's web site at devierkoeden.com Do you like this site? Found an interesting article on this site? Got inspired by something you read here? Then consider making a donation with PayPal. Rate event log this item Like this article? Or do you think it sucks? Make yourself heard by casting your vote below. 1 2 3 4 5 (Sucks) (Rules) Total number of ratings: 95 Follow me on Twitter Want to be notified of new posts on this web site? Then follow me on Twitter. Logging Errors to the Event Log in ASP.NET Applications Let's face c# write to it. We're not living in a perfect world. I am not a perfect programmer, and the same probably applies to you (otherwise you would be stinkin' rich, laying on the beach somewhere drinking a Bacardi and Coke, instead of reading this article). Because we aren't perfect, we know we are going to run into errors in the applications we write sooner or later. This article will explain how you can catch these errors in your ASP.NET applications and log them to the Windows Event log, so it's easy to review them later. The article focuses on ASP.NET, but the principle applies to other .NET applications as well. Prerequisites In this article, I am going to use Visual Studio .NET 2003, so it's handy if you have that to your availability. Visual Studio .NET 2002 will do as well, and you can even follow along if you program in Notepad and use the command line compilers. I'll be using C# as the main language, but you could easily write the code in Visual Basic .NET. Errors? What Errors? I compiled the application and it looks fine! Wit
here for a quick overview of the site Help Center Detailed answers to any questions you might 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, just like you, helping each other. Join them; it only takes a minute: Sign up Writing to an event log in ASP.NET on Windows Server 2008 IIS7 up vote 22 down vote favorite 7 I'm trying to use log4net to write to a customer event log under IIS7 on Windows Server 2008 SP1. However, account doesn't seem to have access to write to the event log. Does anyone have any suggestions? asp.net iis iis-7 share|improve this question edited Apr 21 '09 at 21:12 hlovdal 15.2k65399 asked Apr 3 '09 at 0:59 mhenderson 113114 add a comment| 4 Answers 4 active oldest votes up vote 52 down vote accepted The problem is probably your event source. You have to create an event source before you can write to the event log (if you don't, the Event log object tries to create one for you "automagically" the first time you write to the log). You have to have hightened permissions to create an event log source. In some of my web apps, I have put the code to create the event source into my setup (setup runs as admin, so I'm always guaranteed to be able to create the source). You just have to create the source once. After that, your ASP.Net app should have sufficient permissions to write entries specifying the source (or sources) that you created. You can use an EventLogInstaller in your setup to create the source, or you could just write a little utility to call EventLog.CreateEventSource() as an admin. I'll show you both ways: // You would do this one from within an Installer class in a setup: private void InstallEventLog() { EventLogInstaller logInstaller; //Create an instance of an EventLogInstaller. logInstaller = new EventLogInstaller(); //Set the source name of the event log. logInstaller.Source = "TheEventSourceName"; Installers.Add(logInstaller); } Method 2: just call CreateEventSource once as an admin (you could put the following code into a console app, for example, and run the console app as admin EventLog.CreateEventSource("TheSourceName", "Application"); Bonus: If you have Powershell installed on your server, you can do it from the Powershell com