C# – log4net/c# – Different layout based on the level

clog4net

Is there any way to have different layout based on level of the log message when using log4net? Say, if it is a fatal error, I want to see all kind of information possible – class name, method name, line number etc. But for normal, debug and warning, I want to see only the message (I hope, this can increase the performance).

I am using log4net in C# WinForms. My requirement is to log all the previous 512 messages in to a file when a fatal error occures, and I want to see class name, method name, line number etc only for Fatal errors, for all other levels, just a message.

Best Answer

This post has a good explanation of a log4net config file:

log4net Configuration

Pay attention to the layout elements in the appenders. They define the pattern for how the error and any information you choose are output.