log4net process id information

You can add any properties you want to the GlobalContext. I use this context to store the process id, like this:

log4net.GlobalContext.Properties["pid"] = Process.GetCurrentProcess().Id;

Then you reference this property from your appender using a regular pattern, like this:

<layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date %property{pid} %level %logger - %message%newline" />
</layout>

You can add as many properties as you want, but because of it’s global nature, it works best for properties that don’t change during your application’s execution.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)