本文整理汇总了C#中System.Diagnostics.StackFrame.GetFileName方法的典型用法代码示例。如果您正苦于以下问题:C# StackFrame.GetFileName方法的具体用法?C# StackFrame.GetFileName怎么用?C# StackFrame.GetFileName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Diagnostics.StackFrame
的用法示例。
在下文中一共展示了StackFrame.GetFileName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Format
private static LogInfo Format(string msg, Exception ex = null)
{
var f = new StackFrame(6, true);
var method = f.GetMethod();
var fileInfo = string.Format("{0}[{1}]", f.GetFileName(), f.GetFileLineNumber());
if (ex != null)
{
method = ex.TargetSite;
}
var result = new LogInfo
{
Method = string.Format("{0} {1}",
method.DeclaringType,
method.Name),
Message = msg,
File = string.Empty,
Detail = string.Empty
};
result.File = fileInfo;
if (ex != null)
{
result.Detail = ex.Format();
}
return result;
}
示例2: GetStackItem
// сформировать данные о фрейме стека
private static StackItem GetStackItem(StackFrame sf)
{
if( sf == null )
return null;
MethodBase method = sf.GetMethod();
if( method == null || method.ReflectedType == null )
return null;
// получить информацию о данном фрейме стека
StackItem item = new StackItem();
item.Module = method.Module.Assembly.FullName;
item.ClassName = method.ReflectedType.Name;
item.MethodName = method.Name;
item.FileName = sf.GetFileName();
item.Line = sf.GetFileLineNumber();
// получить параметры данного метода
StringBuilder parameters = new StringBuilder();
ParameterInfo[] paramsInfo = method.GetParameters();
for( Int32 i = 0; i < paramsInfo.Length; i++ )
{
ParameterInfo currParam = paramsInfo[ i ];
parameters.Append( currParam.ParameterType.Name );
parameters.Append( " " );
parameters.Append( currParam.Name );
if( i != paramsInfo.Length - 1 )
parameters.Append( ", " );
}
item.Params = parameters.ToString();
return item;
}
示例3: GetWebRootFileSystemDirectory
public static string GetWebRootFileSystemDirectory(string debugPath = null)
{
string fileSystemWebRoot = null;
try
{
if (!string.IsNullOrEmpty(debugPath))
{
var sf = new StackFrame(0, true);
var fileName = sf.GetFileName();
var sourceWebRootDirectory = string.IsNullOrEmpty(fileName)
? ""
: Path.GetFullPath(Path.Combine(fileName, @"..\..\..", debugPath));
fileSystemWebRoot = Directory.Exists(sourceWebRootDirectory)
? sourceWebRootDirectory
: AppDomain.CurrentDomain.BaseDirectory;
}
else
{
fileSystemWebRoot = AppDomain.CurrentDomain.BaseDirectory;
}
}
catch (Exception)
{
fileSystemWebRoot = AppDomain.CurrentDomain.BaseDirectory;
}
return fileSystemWebRoot;
}
示例4: ShowVsAssert
private static void ShowVsAssert(string stackTrace, StackFrame frame, string message, string detailMessage) {
int[] disable = new int[1];
try {
string detailMessage2;
if (detailMessage == null)
detailMessage2 = stackTrace;
else
detailMessage2 = detailMessage + Environment.NewLine + stackTrace;
string fileName = (frame == null) ? string.Empty : frame.GetFileName();
if (fileName == null) {
fileName = string.Empty;
}
int lineNumber = (frame == null) ? 0 : frame.GetFileLineNumber();
int returnCode = VsAssert(detailMessage2, message, fileName, lineNumber, disable);
if (returnCode != 0) {
if (!System.Diagnostics.Debugger.IsAttached) {
System.Diagnostics.Debugger.Launch();
}
System.Diagnostics.Debugger.Break();
}
if (disable[0] != 0)
ignoredAsserts[MakeAssertKey(fileName, lineNumber)] = null;
}
catch (Exception) {
vsassertPresent = false;
}
}
示例5: StackFrameItem
/// <summary>
/// returns a stack frame item from a stack frame. This
/// </summary>
/// <param name="frame"></param>
/// <returns></returns>
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 + ')';
}
示例6: ExceptionFrame
/// <summary>
/// Initializes a new instance of the <see cref="ExceptionFrame"/> class.
/// </summary>
/// <param name="frame">The <see cref="StackFrame"/>.</param>
public ExceptionFrame(StackFrame frame)
{
if (frame == null)
return;
int lineNo = frame.GetFileLineNumber();
if (lineNo == 0)
{
//The pdb files aren't currently available
lineNo = frame.GetILOffset();
}
var method = frame.GetMethod();
if (method != null)
{
Module = (method.DeclaringType != null) ? method.DeclaringType.FullName : null;
Function = method.Name;
Source = method.ToString();
}
else
{
// on some platforms (e.g. on mono), StackFrame.GetMethod() may return null
// e.g. for this stack frame:
// at (wrapper dynamic-method) System.Object:lambda_method (System.Runtime.CompilerServices.Closure,object,object))
Module = "(unknown)";
Function = "(unknown)";
Source = "(unknown)";
}
Filename = frame.GetFileName();
LineNumber = lineNo;
ColumnNumber = frame.GetFileColumnNumber();
}
示例7: ConeStackFrame
public ConeStackFrame(StackFrame frame)
{
Method = frame.GetMethod();
File = frame.GetFileName();
Line = frame.GetFileLineNumber();
Column = frame.GetFileColumnNumber();
}
示例8: logError
/// bulk of code written by: Alex Marcum - 11/20/2012
public static void logError(Exception ex)
{
System.Diagnostics.StackFrame stackFrame = new System.Diagnostics.StackFrame(1, true);
//System.IO.FileInfo temp = new System.IO.FileInfo(fileName);
//fileName = temp.Name;
//Class Name is the Whole path to the Filename
string fileName = stackFrame.GetFileName();
string functionName = stackFrame.GetMethod().Name.ToString();
int line = stackFrame.GetFileLineNumber();
try
{
using (CCSEntities db = new CCSEntities())
{
ErrorLog el = new ErrorLog();
el.TimeStamp = DateTime.Now;
el.FileName = fileName;
el.FunctionName = functionName;
el.LineNumber = line.ToString();
el.ErrorText = ex.Message;
db.ErrorLogs.Add(el);
db.SaveChanges();
}
}
catch (Exception /*ex*/)
{
}
}
示例9: TestMethodInfo
public TestMethodInfo(StackFrame callingFrame)
{
SourceFileDirectory = Path.GetDirectoryName(callingFrame.GetFileName());
var realMethod = GetRealMethod(callingFrame.GetMethod());
MethodName = realMethod.Name;
DeclaringTypeName = realMethod.DeclaringType?.Name;
}
示例10: StackFrameToString
public static string StackFrameToString(StackFrame stackFrame)
{
StringBuilder sb = new StringBuilder();
int intParam; MemberInfo mi = stackFrame.GetMethod();
sb.Append(" ");
sb.Append(mi.DeclaringType.Namespace);
sb.Append(".");
sb.Append(mi.DeclaringType.Name);
sb.Append(".");
sb.Append(mi.Name);
// -- build method params
sb.Append("(");
intParam = 0;
foreach (ParameterInfo param in stackFrame.GetMethod().GetParameters())
{
intParam += 1;
sb.Append(param.Name);
sb.Append(" As ");
sb.Append(param.ParameterType.Name);
}
sb.Append(")");
sb.Append(Environment.NewLine);
// -- if source code is available, append location info
sb.Append(" ");
if (string.IsNullOrEmpty(stackFrame.GetFileName()))
{
sb.Append("(unknown file)");
//-- native code offset is always available
sb.Append(": N ");
sb.Append(string.Format("{0:#00000}", stackFrame.GetNativeOffset()));
}
else
{
sb.Append(Path.GetFileName(stackFrame.GetFileName()));
sb.Append(": line ");
sb.Append(string.Format("{0:#0000}", stackFrame.GetFileLineNumber()));
sb.Append(", col ");
sb.Append(string.Format("{0:#00}", stackFrame.GetFileColumnNumber()));
if (stackFrame.GetILOffset() != StackFrame.OFFSET_UNKNOWN)
{
sb.Append(", IL ");
sb.Append(string.Format("{0:#0000}", stackFrame.GetILOffset()));
}
}
sb.Append(Environment.NewLine);
return sb.ToString();
}
示例11: Log
static void Log(object message)
{
StackFrame frame = new StackFrame(1, true);
var method = frame.GetMethod();
var fileName = frame.GetFileName();
var lineNumber = frame.GetFileLineNumber();
Console.WriteLine("{0}({1}):{2} - {3}", fileName, lineNumber, method.Name, message);
}
示例12: GetExtraInfo
static string GetExtraInfo (StackFrame sf = null)
{
string threadid = String.Format ("thread_id: {0}", Thread.CurrentThread.ManagedThreadId.ToString ("x"));
string domainid = String.Format ("appdomain_id: {0}", AppDomain.CurrentDomain.Id.ToString ("x"));
string filepath = sf == null ? null : sf.GetFileName ();
int lineNumber = sf == null ? -1 : sf.GetFileLineNumber ();
string format = String.IsNullOrEmpty (filepath) ? " [{0}, {1}]" : " [{0}, {1}, in {2}:{3}]";
return String.Format (format, domainid, threadid, filepath, lineNumber);
}
示例13: toString
// private static readonly Log log = Log.getLog(typeof(FaultSerializer));
private static String toString(StackFrame frame)
{
String answer = "";
MethodBase method = frame.GetMethod();
if( null != method )
{
answer += "[";
Type declaringType = method.DeclaringType;
if (null != declaringType)
{
String moduleName = declaringType.Name;
if (null != moduleName)
{
answer += moduleName;
}
}
String methodName = method.Name;
if (null != methodName)
{
answer += " ";
answer += methodName;
}
answer += "]";
}
if( 0 != answer.Length ) {
answer += " ";
}
String fileName = frame.GetFileName();
if (null == fileName || 0 == fileName.Length)
{
fileName = "?";
}
else
{
int lastSlash = fileName.LastIndexOf('\\');
if (-1 != lastSlash)
{
fileName = fileName.Substring(lastSlash+1); // +1 to skip over the '\'
}
}
String lineNumber = "?";
if (0 != frame.GetFileLineNumber())
{
lineNumber = String.Format("{0}", frame.GetFileLineNumber());
}
answer += String.Format("({0}:{1})", fileName, lineNumber);
return answer;
}
示例14: log
public void log(string strLevel, object objEvent)
{
StackFrame sf = new StackFrame(1, true);
string strMethodName = sf.GetMethod().Name;
string strFname = sf.GetFileName();
string strFileName = System.IO.Path.GetFileName(strFname);
string strEvent = JsonConvert.SerializeObject(objEvent);
this.log(strFileName, strMethodName, strLevel, strEvent);
}
示例15: ExtractInfo
private static string ExtractInfo(string message)
{
StackFrame frame1 = new StackFrame(2, true);
string methodName = frame1.GetMethod().ToString();
string fileName = Path.GetFileName(frame1.GetFileName());
string[] textArray1 = new[] { "File:", fileName, " - Method:", methodName, " - ", message } ;
return string.Concat(textArray1);
}