本文整理汇总了C#中System.Diagnostics.StackTrace.GetFileName方法的典型用法代码示例。如果您正苦于以下问题:C# StackTrace.GetFileName方法的具体用法?C# StackTrace.GetFileName怎么用?C# StackTrace.GetFileName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Diagnostics.StackTrace
的用法示例。
在下文中一共展示了StackTrace.GetFileName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Log
public void Log(string type, string message, LogLevel level)
{
string msg = message;
if (!string.IsNullOrWhiteSpace(type)) msg = string.Format("[{0}]{1}", type, message);
if (level == LogLevel.Debug)
{
StackFrame x = new StackTrace(true).GetFrame(1);
string MethodName = x.GetMethod().Name;
string Filename = x.GetFileName();
int Line = x.GetFileLineNumber();
msg = string.Format("[{0,-3}]{1,-12}:{2,-4} {3}",
MethodName,
Filename,
Line,
msg);
}
TDebugInfo db = new TDebugInfo()
{
Level = level,
Text = msg,
};
if (this.OnLog != null)
{
OnLog(this, new LogArgs() { DebugInfo = db });
}
}
示例2: Ping
internal static void Ping()
{
return; //NO-OP
StackFrame sf = new StackTrace(new StackFrame(1, true)).GetFrame(0);
string file = sf.GetFileName();
int line = sf.GetFileLineNumber();
Dictionary<int, ScopedTimerRecord> filedict;
ScopedTimerRecord linerecord;
lock (records)
{
if (!records.ContainsKey(file))
{
records.Add(file, new Dictionary<int, ScopedTimerRecord>());
}
filedict = records[file];
}
lock(filedict)
{
if (!filedict.ContainsKey(line))
{
filedict.Add(line, new ScopedTimerRecord(file, line));
}
linerecord = filedict[line];
}
linerecord.update();
}
示例3: SPDException
/// <summary>
/// Initializes a new instance of the <see cref="SPDException"/> class.
/// </summary>
/// <param name="inner">The inner.</param>
/// <param name="message">The message.</param>
/// <param name="url">The URL.</param>
public SPDException(Exception inner, string message, string url)
: base(message, inner)
{
StackFrame frame = new System.Diagnostics.StackTrace(true).GetFrame(1);
this.where = "File: " + frame.GetFileName() + Environment.NewLine + "Method: " + frame.GetMethod().Name + Environment.NewLine + "Line: " + frame.GetFileLineNumber() + Environment.NewLine + "Col: " + frame.GetFileColumnNumber();
this.url = url;
}
示例4: Append
public void Append(string m, ROSOUT_LEVEL lvl, int level=1)
{
StackFrame sf = new StackTrace(new StackFrame(level,true)).GetFrame(0);
Log l = new Log {msg = new m.String(m), level = ((byte) ((int) lvl)), name = new m.String(this_node.Name), file = new m.String(sf.GetFileName()), function = new m.String(sf.GetMethod().Name), line = (uint)sf.GetFileLineNumber()};
string[] advert = this_node.AdvertisedTopics().ToArray();
l.topics = new m.String[advert.Length];
for (int i = 0; i < advert.Length; i++)
l.topics[i] = new m.String(advert[i]);
lock (queue_mutex)
log_queue.Enqueue(l);
}
示例5: Error
public Error(Exception ex)
{
Message = ex.Message;
StackTrace = ex.StackTrace;
Type = ex.GetType().Name;
Source = ex.Source;
var frame = new StackTrace(ex, true).GetFrame(0);
if (frame != null)
{
FileName = frame.GetFileName();
LineNumber = frame.GetFileLineNumber();
SourceCode = ExceptionHelper.GetSourceFileLines(FileName, Encoding.Default, Source, LineNumber);
}
}
示例6: DebugLog
public void DebugLog(Exception e, DebugLevel Level)
{
StackFrame x = new StackTrace(e).GetFrame(0);
string MethodName = x.GetMethod().Name;
string Filename = x.GetFileName();
int Line = x.GetFileLineNumber();
TDebugInfo db = new TDebugInfo()
{
Filename = Filename,
Level = DebugLevel.F,
Line = Line,
MethodName = MethodName,
Text = e.Message + Environment.NewLine + e.StackTrace,
Time = DateTime.Now
};
if(DebugList.Count > DebugCount)
DebugList.RemoveAt(0);
DebugList.Add(db);
OnError(this, new LogArgs() { DebugInfo = db });
}
示例7: Append
private void Append(string m, ROSOUT_LEVEL lvl, int level)
{
StackFrame sf = new StackTrace(new StackFrame(level, true)).GetFrame(0);
Log logmsg = new Log
{
msg = m, name = this_node.Name, file = sf.GetFileName(), function = sf.GetMethod().Name, line = (uint) sf.GetFileLineNumber(), level = ((byte) ((int) lvl)),
header = new m.Header() { stamp = ROS.GetTime() }
};
TopicManager.Instance.getAdvertisedTopics(out logmsg.topics);
lock (log_queue)
log_queue.Enqueue(logmsg);
}
示例8: Write
/// <summary>
/// Writes the specified messages to the log.
/// </summary>
/// <param name="level">The weight of the message.</param>
/// <param name="message">The message to log.</param>
private static void Write(Level level, string message)
{
var frm = new StackTrace(2, true).GetFrame(0);
var log = string.Format("[{0:yyyy-MM-dd HH:mm:ss} / {1}] {2}:{3} / {4}.{5}(): {6}", DateTime.Now, level.ToString().ToUpper(), Path.GetFileName(frm.GetFileName()), frm.GetFileLineNumber(), frm.GetMethod().DeclaringType.FullName, frm.GetMethod().Name, message);
}
示例9: MISUSE_BKPT
internal static RC MISUSE_BKPT()
{
var sf = new StackTrace(new StackFrame(true)).GetFrame(0);
LOG(RC.CANTOPEN, "misuse at line {0} of [{1}]", sf.GetFileLineNumber(), sf.GetFileName());
return RC.MISUSE;
}
示例10: WarnOnIncorrectName
protected void WarnOnIncorrectName(string name) {
System.Diagnostics.StackFrame stackFrame = new System.Diagnostics.StackTrace().GetFrame(1);
string callerIdMessage = ". Called by {0}.{1}().".Inject(stackFrame.GetFileName(), stackFrame.GetMethod().Name);
Debug.LogWarning("Name used in PopupList not found: " + name + callerIdMessage);
}
示例11: IsSecure
private bool IsSecure(NancyContext context)
{
//If we're directly access via a secure scheme everything is ok
if (context.Request.Url.IsSecure)
return true;
//We might be directly accessed via an insecure scheme because a reverse proxy did https termination already, check if a header has been set indicating this
if (context.Request.Headers.Keys.Contains("X-Forwarded-Protocol") && context.Request.Headers["X-Forwarded-Protocol"].Contains("https"))
return true;
if (context.Request.Headers.Keys.Contains("X-Forwarded-Proto") && context.Request.Headers["X-Forwarded-Proto"].Contains("https"))
return true;
#if DEBUG
var frame = new StackTrace(true).GetFrame(0);
Console.WriteLine("Skipping HTTPS check (DEBUG MODE) {0} Ln{1}", frame.GetFileName(), frame.GetFileLineNumber());
return true;
#else
return false;
#endif
}
示例12: ErrorToUserLog
//protected void Page_Error(object sender, EventArgs e)
//{
// //ErrorToUserLog();
//}
private void ErrorToUserLog()
{
try
{
Exception exc = Server.GetLastError();
string source = Request.QueryString["handler"];
bool Error = true;
string ErrorMessage = "";
if (exc.InnerException != null)
{
ErrorMessage += "Inner Exception Type: ";
ErrorMessage += exc.InnerException.GetType().ToString();
ErrorMessage += "\n\nInner Exception: ";
ErrorMessage += exc.InnerException.Message;
ErrorMessage += "\n\nInner Source: ";
ErrorMessage += exc.InnerException.Source;
if (exc.InnerException.StackTrace != null)
{
ErrorMessage += "\nInner Stack Trace: ";
ErrorMessage += exc.InnerException.StackTrace;
}
}
var frame = new StackTrace(exc, true).GetFrame(0);
var sourceFile = frame.GetFileName();
var lineNumber = frame.GetFileLineNumber();
ErrorMessage += "\n\nSource File: " + sourceFile + "\nLine Number: " + lineNumber;
ErrorMessage += "\n\nException Type: ";
ErrorMessage += exc.GetType().ToString();
ErrorMessage += "\n\nException: " + exc.Message;
ErrorMessage += "\n\nSource: " + source;
ErrorMessage += "\n\nStack Trace: ";
if (exc.StackTrace != null)
{
ErrorMessage += exc.StackTrace;
}
ErrorMessage += "\n\n\n" + exc.ToString();
ParseObject error = new ParseObject("Error");
error["errorMessage"] = ErrorMessage;
if (LoggedIn)
{
error["user"] = PublicUserData.ObjectId;
}
error.SaveAsync();
Response.Redirect("Error");
}
catch
{ }
}
示例13: Log
// protected because supposes that caller is two levels up
protected void Log(Level level, object message)
{
if (IsLevelEnabled(level))
{
StackFrame frame = new System.Diagnostics.StackTrace(true).GetFrame(2);
string method = frame.GetMethod().Name;
string file = frame.GetFileName();
int line = frame.GetFileLineNumber();
Log(level, message.ToString(), file, line, method);
}
}
示例14: CANTOPEN_BKPT
internal static RC CANTOPEN_BKPT()
{
var sf = new StackTrace(new StackFrame(true)).GetFrame(0);
LOG(RC.CANTOPEN, "cannot open file at line {0} of [{1}]", sf.GetFileLineNumber(), sf.GetFileName());
return RC.CANTOPEN;
}
示例15: LogException
internal static void LogException(object sender, Exception e, string currentAction)
{
var stackTrace = new StackTrace(e, true).GetFrame(0);
Log(sender, $"An unhandled exception (type: {e.GetType()}) occurred while {currentAction}. Exception message: \"{e.Message}\"; in file:{stackTrace.GetFileName()}:{stackTrace.GetFileLineNumber()}", LogLevel.Error);
}