#if !NETCF
#region Apache License
//
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to you under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#endregion
using System;
using System.Diagnostics;
using System.Reflection;
using log4net.Util;
namespace log4net.Core
{
///
/// provides stack frame information without actually referencing a System.Diagnostics.StackFrame
/// as that would require that the containing assembly is loaded.
///
///
[Serializable]
public class StackFrameItem
{
#region Public Instance Constructors
///
/// returns a stack frame item from a stack frame. This
///
///
///
public StackFrameItem(StackFrame frame)
{
// set default values
m_lineNumber = NA;
m_fileName = NA;
m_method = new MethodItem();
m_className = NA;
try
{
// get frame values
m_lineNumber = frame.GetFileLineNumber().ToString(System.Globalization.NumberFormatInfo.InvariantInfo);
m_fileName = frame.GetFileName();
// get method values
MethodBase method = frame.GetMethod();
if (method != null)
{
if(method.DeclaringType != null)
m_className = method.DeclaringType.FullName;
m_method = new MethodItem(method);
}
}
catch (Exception ex)
{
LogLog.Error(declaringType, "An exception ocurred while retreiving stack frame information.", ex);
}
// set full info
m_fullInfo = m_className + '.' + m_method.Name + '(' + m_fileName + ':' + m_lineNumber + ')';
}
#endregion
#region Public Instance Properties
///
/// Gets the fully qualified class name of the caller making the logging
/// request.
///
///
/// The fully qualified class name of the caller making the logging
/// request.
///
///
///
/// Gets the fully qualified class name of the caller making the logging
/// request.
///
///
public string ClassName
{
get { return m_className; }
}
///
/// Gets the file name of the caller.
///
///
/// The file name of the caller.
///
///
///
/// Gets the file name of the caller.
///
///
public string FileName
{
get { return m_fileName; }
}
///
/// Gets the line number of the caller.
///
///
/// The line number of the caller.
///
///
///
/// Gets the line number of the caller.
///
///
public string LineNumber
{
get { return m_lineNumber; }
}
///
/// Gets the method name of the caller.
///
///
/// The method name of the caller.
///
///
///
/// Gets the method name of the caller.
///
///
public MethodItem Method
{
get { return m_method; }
}
///
/// Gets all available caller information
///
///
/// All available caller information, in the format
/// fully.qualified.classname.of.caller.methodName(Filename:line)
///
///
///
/// Gets all available caller information, in the format
/// fully.qualified.classname.of.caller.methodName(Filename:line)
///
///
public string FullInfo
{
get { return m_fullInfo; }
}
#endregion Public Instance Properties
#region Private Instance Fields
private readonly string m_lineNumber;
private readonly string m_fileName;
private readonly string m_className;
private readonly string m_fullInfo;
private readonly MethodItem m_method;
#endregion
#region Private Static Fields
///
/// The fully qualified type of the StackFrameItem class.
///
///
/// Used by the internal logger to record the Type of the
/// log message.
///
private static readonly Type declaringType = typeof(StackFrameItem);
///
/// When location information is not available the constant
/// NA is returned. Current value of this string
/// constant is ?.
///
private const string NA = "?";
#endregion Private Static Fields
}
}
#endif