This is a new answer to an old question, but maybe its helpful to someone.
I didn t like the long quartz thread name [DefaultQuartzScheduler_Worker-1] in my log files.
Instead I wanted log4net to show the thread id. Therefor you need to set a property that logs the current thread s id.
I found this class. source
This is a lambda / func way of logging calculated context: log4net context explained
public class Log4NetContextProperty : IFixingRequired
{
private readonly Func<string> _getValue;
public Log4NetContextProperty(Func<string> getValue)
{
_getValue = getValue;
}
public override string ToString()
{
return _getValue();
}
public object GetFixedObject()
{
return ToString();
}
}
And you have to call it this way in your application start place.
log4net.GlobalContext.Properties["threadId"] = new Log4NetContextProperty(() => Thread.CurrentThread.ManagedThreadId.ToString());
Then in your log4net config adapt the conversionpattern to include the new property.
Mine looks like this:
<conversionPattern value="%d{dd.MM.yyyy HH:mm:ss,ffff} %-5level [%property{threadId}] - %message%newline" />
That s it. This way the id of each thread will be determinded at runtime and logged in its own property.