How to log stack trace using log4net (C#)

Use this:

void Error(object message,Exception t)

Reason is in log4net documentation for void Error(object message):

WARNING Note that passing an Exception to this method will print the name of the Exception but no stack trace. To print a stack trace use the void Error(object,Exception) form instead.

Error(object message, Exception t) is the most flexible way to log exception data because it goes as an Exception rather than Object and that can be used in appenders to narrow logs to a particular exception class (rather than by searching for a string which is much slower and less consistent)

There are special versions of all non-format logging methods that take message and exception:

namespace log4net
{
    public interface ILog
    {
        ...
        /* Log a message object and exception */
        void Debug(object message, Exception t);
        void Info(object message, Exception t);
        void Warn(object message, Exception t);
        void Error(object message, Exception t);
        void Fatal(object message, Exception t);
        ...
    }
}

You need to ensure that the definition of the layout pattern is structured to output what format and data you want.

log4Net Pattern Layout

Used to output the stack trace of the logging event The stack trace level specifier may be enclosed between braces. For example, %stacktrace{level}. If no stack trace level specifier is given then 1 is assumed

Output uses the format: type3.MethodCall3 > type2.MethodCall2 > type1.MethodCall1

This pattern is not available for Compact Framework assemblies.