views:

27

answers:

3

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.

A: 

Since the ID is generated by the database and not by log4net, I don't believe this information is available to you.

What I've done in using log4net for such conditions is to include a datetime stamp in the message that goes down to the millisecond and present that to the user as a reference number. You can do then do a simple SQL query to get to the message in the log table.

Russ
A: 

I'm not sure its posible but you can write your own Appender for log4net end store this information in the log4net-context.

Howto writing an appender for log4net:

http://www.alteridem.net/2008/01/10/writing-an-appender-for-log4net/

Context-Description:

http://logging.apache.org/log4net/release/manual/contexts.html

Floyd
A: 

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.

Stefan Egli