-4

I would like to set up something for logging that will capture any exception or such that my projects might run into that I haven't been able to anticipate with say a try{} catch{}.

The project I'm working on has too many possible places where something can happen, and I need to be able to capture those instances and write them out to a log that I can read and be made aware of problems.

I've seen references to log4net, but I'm not familiar enough with it to know if it can log any uncaught exceptions, or other errors.

Thank you.

shadonar
  • 1,114
  • 3
  • 16
  • 40
  • 2
    Have you tried anything at all? – eddie_cat Jun 06 '14 at 15:17
  • I've done the try catch just writing out to a log file, but I haven't used a logging framework because I don't know what can catch those uncaught exceptions. I've used log4net a few years ago but only for very simple logging. – shadonar Jun 06 '14 at 15:19
  • 1
    `log4net` is great for logging, but it won't log unless you tell it. To handle all exceptions you could attach an event handler to the unhandled exception event handler, but then you'd need to cater for the scenarios where your exceptions are handled. – Daniel Kelley Jun 06 '14 at 15:19
  • 1
    *(at least on Windows)* You can call [SetUnhandledExceptionFilter](http://msdn.microsoft.com/en-us/library/windows/desktop/ms680634(v=vs.85).aspx). When your program ends with an unhandled exception, the function you specify will still get called with information about the exception. – abelenky Jun 06 '14 at 15:21
  • Did you try looking into ELMAH? – Rex Jun 06 '14 at 15:29
  • @Rex haven't heard of ELMAH...so, no I haven't. I will look at it. thanks for the info. – shadonar Jun 06 '14 at 15:31
  • @Rex would ELMAH work for a non-web application? I see that it's for ASP.NET code. – shadonar Jun 06 '14 at 15:42
  • 1
    @shadonar check out this [link](http://stackoverflow.com/questions/841451/using-elmah-in-a-console-application) – Rex Jun 06 '14 at 15:46
  • @Rex I think this is going to work for me. Thanks! if you set that as an answer I'll accept it. – shadonar Jun 06 '14 at 15:55

1 Answers1

1

Use ELMAH for logging your errors, follow this link as to implement it in winforms.

Community
  • 1
  • 1
Rex
  • 1,134
  • 15
  • 26