Search code examples
log4netadonetappender

Get an entry ID for log4net ADONetAppender


I am using log4net in a web app, and log all page errors to a SQL server. I was wondering if there was any way to retrieve the entry ID generated by it. I'm going off of the documentation found here

http://logging.apache.org/log4net/release/config-examples.html

I want to use this ID as a reference number I can show to a customer so that they may contact customer support to lookup in the system and not have to go through a log file.


Solution

  • Apart from writing your own appender as floyddotnet suggested you could consider:

    1. Use a GUID. You can easily generate it in your application and will serve most of your purposes. Drawback: It may be inconvenient for the customers if they try to tell your support stuff about it on the phone. If you have only email support than this is maybe not an issue.
    2. Consider creating an incident number outside of the logging framework. A quick call to a stored procedure that returns an ID that you save in a nullable field in your log table.
    3. A combination of the above: Use a Guid and after logging you call a stored procedure that creates an incident and returns the ID.

    Writing an appender that returns the ID creates a dependency between your application and appenders that you normally do not have: Log4net was designed with a clear separation between logging and writing the log messages somewhere. The appender that you need would affect that separation.