Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log4NET, ADONetAppender and custom fields

I am able to set up log4NET with the ADONetAppender, and all works fine when I want to capture the state of things when I log a message via log.Info(message).

As I will be logging from various locations in my application based on an ActionID which changes throughout the application, how do I extend things so that I may instead issue a call such as log.Info(ActionID, message), with ActionID ending up in the database?

like image 920
John Smith Avatar asked Dec 21 '22 12:12

John Smith


1 Answers

You can add custom fields to log4net using GlobalContext.Properties before calling log.Info() by doing something like this:

GlobalContext.Properties["ActionID"] = ActionID;

Then, in your ADONetAppender configuration, you can access this custom field with %property{ActionID}.

like image 111
Brandon Wood Avatar answered Dec 23 '22 03:12

Brandon Wood