Index: Core/LocationInfo.cs =================================================================== --- Core/LocationInfo.cs (revision 1225075) +++ Core/LocationInfo.cs (working copy) @@ -56,6 +56,7 @@ /// /// Nicko Cadell /// Gert Driesen + /// Adam Davies #if !NETCF [Serializable] #endif @@ -127,7 +128,7 @@ stackFramesList.CopyTo(m_stackFrames, 0); // now frameIndex is the first 'user' caller frame - StackFrame locationFrame = st.GetFrame(frameIndex); + StackFrame locationFrame = m_stackFrames[0]; if (locationFrame != null) { @@ -182,6 +183,61 @@ ':' + m_lineNumber + ')'; } + /// + /// Constructor + /// + /// StackFrames + /// Index for the start location of the Stackframe + /// + /// + /// Initializes a new instance of the + /// class with the specified data. + /// + /// + public LocationInfo(StackFrame[] frames, int offset) + { + if (frames == null) + { + return; + } + + if (offset > frames.Length - 1) + { + offset = frames.Length - 1; + } + + int adjustedFrameCount = frames.Length - offset; + ArrayList stackFramesList = new ArrayList(adjustedFrameCount); + m_stackFrames = new StackFrame[adjustedFrameCount]; + for (int i = offset; i < frames.Length; i++) + { + stackFramesList.Add(frames[i]); + } + + stackFramesList.CopyTo(m_stackFrames, 0); + + StackFrame locationFrame = m_stackFrames[0]; + + if (locationFrame != null) + { + System.Reflection.MethodBase method = locationFrame.GetMethod(); + + if (method != null) + { + m_methodName = method.Name; + if (method.DeclaringType != null) + { + m_className = method.DeclaringType.FullName; + } + } + m_fileName = locationFrame.GetFileName(); + m_lineNumber = locationFrame.GetFileLineNumber().ToString(System.Globalization.NumberFormatInfo.InvariantInfo); + + // Combine all location info + m_fullInfo = m_className + '.' + m_methodName + '(' + m_fileName + ':' + m_lineNumber + ')'; + } + } + #endregion Public Instance Constructors #region Public Instance Properties Index: Layout/XMLLayout.cs =================================================================== --- Layout/XMLLayout.cs (revision 1225075) +++ Layout/XMLLayout.cs (working copy) @@ -69,6 +69,7 @@ /// /// Nicko Cadell /// Gert Driesen + /// /// Adam Davies public class XmlLayout : XmlLayoutBase { #region Public Instance Constructors @@ -297,7 +298,10 @@ if (LocationInfo) { LocationInfo locationInfo = loggingEvent.LocationInformation; - + if (LocationOffset > 0) + { + locationInfo = new LocationInfo(loggingEvent.LocationInformation.StackFrames, LocationOffset); + } writer.WriteStartElement(m_elmLocation); writer.WriteAttributeString(ATTR_CLASS, locationInfo.ClassName); writer.WriteAttributeString(ATTR_METHOD, locationInfo.MethodName); Index: Layout/XMLLayoutBase.cs =================================================================== --- Layout/XMLLayoutBase.cs (revision 1225075) +++ Layout/XMLLayoutBase.cs (working copy) @@ -41,6 +41,7 @@ /// /// Nicko Cadell /// Gert Driesen + /// Adam Davies abstract public class XmlLayoutBase : LayoutSkeleton { #region Protected Instance Constructors @@ -86,6 +87,31 @@ #region Public Instance Properties + /// + /// Gets or sets a value indicating where to begin reading the stacktrace + /// as relative to its current position. + /// + /// + /// 0 to begin at current stack location; otherwise, index to begin at the + /// current stack + index. + /// + public int LocationOffset + { + get { return m_locationOffset; } + set + { + //Ignore values less than zero + if (value >= 0) + { + m_locationOffset = value; + } + else + { + m_locationOffset = 0; + } + } + } + /// /// Gets a value indicating whether to include location information in /// the XML events. @@ -231,7 +257,12 @@ #endregion Protected Instance Methods #region Private Instance Fields - + + /// + /// Indicates the stacktrace offset (requires m_locationinfo == true) + /// + private int m_locationOffset = 0; + /// /// Flag to indicate if location information should be included in /// the XML events.