What are the best practices for including logging using log4net?

后端 未结 9 992
夕颜
夕颜 2021-02-07 04:04

I have been told to add “logging” to my code using log4net, the problem is no one can travel in time and see what real world problems the logging will need to be used to solve.<

9条回答
  •  攒了一身酷
    2021-02-07 04:56

    Logging is not an easy task, but my experience is that all logs should be searchable for responsible parties. An useful target for errors are email directly (and in some cases sms). But in the end all logging data should be searchable in a database with a sesible user interface.

    When the email is received to a specific account, this can be processed and put in the database directly. There are som categories and handling rules below:

    • Critical errors: should be availbale immediatly email/sms
    • Future issues: daily/weekly email
    • Debug info ==> daily/weekly email with a notification on how much debug info is produces since last time.

    The content of the debugging can be written to the database in different way, but we need to concider performance. Large amount of data should not be written to database in "production mode". This should be done in daily/weekly bases. The best way is to produce a local file (such as XML or plain text) and put this file into the database during maintenance hours (at night). It should be possible to start/stop a debug session and only write the debug information to the database when the debug session is completed.

    The debug component could be implemented as a WCF and log2net and directy access to the database and/or a local file store that is put into the database on regular basis.

    One thing is clear...ALL errors/exception should be logged somewhere. Nothing is more irritating than lost error messages :)

    Happy debugging!

提交回复
热议问题