Index: ExceptionPatternConverter.cs =================================================================== --- ExceptionPatternConverter.cs (revision 426364) +++ ExceptionPatternConverter.cs (working copy) @@ -21,6 +21,7 @@ using System.IO; using log4net.Core; +using log4net.Util; namespace log4net.Layout.Pattern { @@ -64,7 +65,8 @@ /// trailing newline. /// /// - /// If there is no exception then nothing will be output + /// If there is no exception or the exception property specified + /// by the Option value does not exist then nothing will be output /// and no trailing newline will be appended. /// It is typical to put a newline before the exception /// and to have the exception as the last data in the pattern. @@ -72,11 +74,45 @@ /// override protected void Convert(TextWriter writer, LoggingEvent loggingEvent) { - string exceptionString = loggingEvent.GetExceptionString(); - if (exceptionString != null && exceptionString.Length > 0) + if (loggingEvent.ExceptionObject != null && Option != null) { - writer.WriteLine(exceptionString); + if (0 == String.Compare(Option, "Message", true)) + { + writer.Write(loggingEvent.ExceptionObject.Message); + } + else if (0 == String.Compare(Option, "Source", true)) + { + writer.Write(loggingEvent.ExceptionObject.Source); + } + else if (0 == String.Compare(Option, "StackTrace", true)) + { + writer.Write(loggingEvent.ExceptionObject.StackTrace); + } + else if (0 == String.Compare(Option, "TargetSite", true)) + { + WriteObject(writer, loggingEvent.Repository, loggingEvent.ExceptionObject.TargetSite); + } + else if (0 == String.Compare(Option, "HelpLink", true)) + { + writer.Write(loggingEvent.ExceptionObject.HelpLink); + } + else + { + // do not output SystemInfo.NotAvailableText + } } + else + { + string exceptionString = loggingEvent.GetExceptionString(); + if (exceptionString != null && exceptionString.Length > 0) + { + writer.WriteLine(exceptionString); + } + else + { + // do not output SystemInfo.NotAvailableText + } + } } } }