Sometimes your logger throws an exception while logging an exception. At least it does if you have luck swings like mine from time to time.
Here's how I deal with it.
using System.Diagnostics;
try{ //some logging code that can throw an exception //but the exception has to be handled and logged //somehow}catch (Exception e){ try { //write exception to OS event log if (!EventLog.SourceExists("MyAppName")) EventLog.CreateEventSource("MyAppName", "Application"); EventLog.WriteEntry("MyAppName", "Log Exception: " + e.Message); } catch { //sorry charlie }}
It's not perfect, but it seems to work in most cases.
This code comes in handy especially in Windows Services where in the .NET Framework 2.0 and up (as near as I can tell), an unhandled exception will result in your service being stopped with little or no evidence as to why.
Page rendered at Tuesday, January 06, 2009 3:38:56 AM (Mountain Standard Time, UTC-07:00)
DisclaimerThe opinions expressed herein are just that, opinions. Don't have a fit if you think they're wrong. Post your comment or write your own blog.