locked
Maintain the exception logs in catch block RRS feed

  • Question

  • User1052662409 posted

    Hi All,

    I am going to implement the exceptional logs for my application.

    So that I can catch and store it into the database.

     try
            {
                // do something
            }
            catch (Exception ex)
            {
    
                // save ex related messages into database
            }

    I need once suggestion( Although I already have known some of the fields like Error Message, inner exception etc.)

    Are there any other important fields/information I am missing to store in database while catching the exception?

    Please suggest.

    Thursday, June 4, 2020 10:09 AM

Answers

  • User475983607 posted

    Hi All,

    I am going to implement the exceptional logs for my application.

    So that I can catch and store it into the database.

     try
            {
                // do something
            }
            catch (Exception ex)
            {
    
                // save ex related messages into database
            }

    I need once suggestion( Although I already have known some of the fields like Error Message, inner exception etc.)

    Are there any other important fields/information I am missing to store in database while catching the exception?

    Please suggest.

    The stack trace and variable state when the exception occurred.  Honestly, you should you should know what you're looking for.   think about it like this, later you'll need to query the table to find exceptions.  How do you intend to query the database and what information do you need to figure out what happened?  Date? Action? Controller? Method?  URL? Request? Exception? 

    Put a little more thought into this feature.  Maybe talk with your team members.   

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 4, 2020 11:38 AM
  • User-939850651 posted

    Hi, demoninside9

    I think that in the record of the exception log, Such as:

    • Time when the exception occurred
    • Request address
    • Type of exception
    • Possible request parameters
    • Status of the request
    • Exception error information

    These information are very helpful for locating vulnerabilities in subsequent maintenance.

    Of course, it also depends on the specific production environment.

    Best regards,

    Xudong Peng

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 5, 2020 9:54 AM

All replies

  • User475983607 posted

    Hi All,

    I am going to implement the exceptional logs for my application.

    So that I can catch and store it into the database.

     try
            {
                // do something
            }
            catch (Exception ex)
            {
    
                // save ex related messages into database
            }

    I need once suggestion( Although I already have known some of the fields like Error Message, inner exception etc.)

    Are there any other important fields/information I am missing to store in database while catching the exception?

    Please suggest.

    The stack trace and variable state when the exception occurred.  Honestly, you should you should know what you're looking for.   think about it like this, later you'll need to query the table to find exceptions.  How do you intend to query the database and what information do you need to figure out what happened?  Date? Action? Controller? Method?  URL? Request? Exception? 

    Put a little more thought into this feature.  Maybe talk with your team members.   

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 4, 2020 11:38 AM
  • User753101303 posted

    Hi,

    Just start with ex.toString() and then depending on the situation:
    - if inside your company, knowing who had the error could be usefull
    - if load balanced servers on which server it happens
    - the current url

    You can always add/remove  later if needed. For example when I started web programming I added posted form fields but with some experience you won't miss them etc...

    Not directly related but if doing nothing more than logging exceptions it should be likely handled at a higher level (you are using ASP.NET 4.x or ASP.NET Core ?) rather than with local try/catch (they are usefull if you want more than your global default exception handling).

    Thursday, June 4, 2020 12:43 PM
  • User303363814 posted

    Don't reinvent the wheel.. Just implement ELMAH

    Friday, June 5, 2020 4:35 AM
  • User-939850651 posted

    Hi, demoninside9

    I think that in the record of the exception log, Such as:

    • Time when the exception occurred
    • Request address
    • Type of exception
    • Possible request parameters
    • Status of the request
    • Exception error information

    These information are very helpful for locating vulnerabilities in subsequent maintenance.

    Of course, it also depends on the specific production environment.

    Best regards,

    Xudong Peng

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 5, 2020 9:54 AM