Add a custom property to include in all log4net messages

Miral picture Miral · Jul 14, 2010 · Viewed 12.7k times · Source

I have a unique identifier which goes through the whole application. I want this 'ID' to be logged as a separate property, so that it's easy to find out in log files or from the database.

Answer

Stefan Egli picture Stefan Egli · Jul 14, 2010

You can use context properties e.g. like this:

ThreadContext.Properties["ID"] = yourID;

then you can access the property in the pattern string like this:

%property{ID}