Thread based Error / Event Logging

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • CrashTECH
    New Member
    • Sep 2008
    • 2

    Thread based Error / Event Logging

    Okay, I have NO idea if this is possible (or a good idea) but I am getting REALLY annoyed...

    So I wrote this error logging class, to specs. It takes 3 objects as parameters, one for the exception, one for System.Relefect ion.MethodBase. GetCurrentMetho d(), and one for a Sql Data object (Data Adapter, Table Adapter, or SQL Command)... spawns a thread, saves info to a DB or dumps a strongly typed dataset to xml...

    no worries.

    BUT

    Code:
    try
    {
         ///Do Stuff....
    }
    catch (Exception Ex)
    {
         ErrorLogging.LogError(Ex, System.Reflection.MethodBase.GetCurrentMethod(), null);
    
    }
    This is a PITA, not to mention, difficult to change if something should change somewhere.

    Is it possible to have some object watching a thread, suck in the relevant information (using Reflection, similar to how I am doing it now) and spawn a child/worker thread to do this? Then it just happens no matter where the exception is?

    This would be a life saver (as well as helping migrate other apps to use this type of error logging). I would like to use it to prevent the app from job closing too if possible. If it traps an error, it should try to gracefully quit what it was doing and move on (button click, throws an error, it just discards what it was doing and ends the event)?
  • pootle
    New Member
    • Apr 2008
    • 68

    #2
    Hi,

    Just out of interest, have you not considered using a logging framework, something like log4net, or my personal favourite, NLog. They are both free and make life much easier - they help with the whole PITA thing. . .

    Comment

    • CrashTECH
      New Member
      • Sep 2008
      • 2

      #3
      I am looking into it actually. It needs to do more than just log the Ex though. We have a local DB (offline application) that we want to store things to and/or write to XML. Do some other things if possible.

      Do you know of any frameworks that support those types of things?

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Are you developing a web application?
        If so, the Global.asax allows you to implement the Application_Err or method. This is called whenever an exception is not caught in the application.

        -Frinny

        Comment

        Working...