本文整理汇总了C#中System.Diagnostics.StackTrace.GetFileLineNumber方法的典型用法代码示例。如果您正苦于以下问题:C# StackTrace.GetFileLineNumber方法的具体用法?C# StackTrace.GetFileLineNumber怎么用?C# StackTrace.GetFileLineNumber使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Diagnostics.StackTrace
的用法示例。
在下文中一共展示了StackTrace.GetFileLineNumber方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: 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 });
}
}
示例3: 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();
}
示例4: LogMethodExit
public static void LogMethodExit(
LOGSEVERITY eSeverity = LOGSEVERITY.Information)
{
var sf = new StackTrace(true).GetFrame(1);
var method = sf.GetMethod();
Log("exit.", eSeverity, sf.GetMethod().Name, sf.GetFileLineNumber(), method.ReflectedType.Name);
}
示例5: LogMethodException
public static void LogMethodException(
string exception,
LOGSEVERITY eSeverity = LOGSEVERITY.Error)
{
var sf = new StackTrace(true).GetFrame(1);
var method = sf.GetMethod();
Log(string.Format("Got exception = {0}!", exception), eSeverity, method.Name, sf.GetFileLineNumber(), method.ReflectedType.Name);
}
示例6: Write
/// <summary>
/// Writes the specified log level.
/// </summary>
/// <param name="logLevel">Used level.</param>
/// <param name="msg">Message.</param>
/// <param name="exception">The exception (or null).</param>
public override void Write(LogLevel logLevel, string msg, Exception exception)
{
var frame = new StackTrace(SkipFrameCount).GetFrame(0);
var caller = frame.GetMethod().ReflectedType.Name + "." +
frame.GetMethod().Name + "():" + frame.GetFileLineNumber();
System.Diagnostics.Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " " + caller.PadRight(50) + logLevel.ToString().PadRight(10) + msg);
if (exception != null)
System.Diagnostics.Debug.WriteLine(BuildExceptionDetails(exception, 4));
}
示例7: 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);
}
示例8: Write
/// <summary>
/// Writes the specified log level.
/// </summary>
/// <param name="logLevel">Used level.</param>
/// <param name="msg">Message.</param>
/// <param name="exception">The exception (or null).</param>
public override void Write(LogLevel logLevel, string msg, Exception exception)
{
var frame = new StackTrace(SkipFrameCount).GetFrame(0);
var caller = frame.GetMethod().ReflectedType.Name + "." +
frame.GetMethod().Name + "():" + frame.GetFileLineNumber();
ConsoleColor color = Console.ForegroundColor;
Console.ForegroundColor= GetColor(logLevel);
Console.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " " + caller.PadRight(50) + logLevel.ToString().PadRight(10) + msg);
if (exception != null)
Console.WriteLine(BuildExceptionDetails(exception, 4));
Console.ForegroundColor = color;
}
示例9: 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);
}
}
示例10: GetProcessHandle
/// <devdoc>
/// Gets a short-term handle to the process, with the given access.
/// If a handle is stored in current process object, then use it.
/// Note that the handle we stored in current process object will have all access we need.
/// </devdoc>
/// <internalonly/>
private SafeProcessHandle GetProcessHandle(int access, bool throwIfExited)
{
#if FEATURE_TRACESWITCH
Debug.WriteLineIf(_processTracing.TraceVerbose, "GetProcessHandle(access = 0x" + access.ToString("X8", CultureInfo.InvariantCulture) + ", throwIfExited = " + throwIfExited + ")");
#if DEBUG
if (_processTracing.TraceVerbose) {
StackFrame calledFrom = new StackTrace(true).GetFrame(0);
Debug.WriteLine(" called from " + calledFrom.GetFileName() + ", line " + calledFrom.GetFileLineNumber());
}
#endif
#endif
if (_haveProcessHandle)
{
if (throwIfExited)
{
// Since haveProcessHandle is true, we know we have the process handle
// open with at least SYNCHRONIZE access, so we can wait on it with
// zero timeout to see if the process has exited.
using (ProcessWaitHandle waitHandle = new ProcessWaitHandle(_processHandle))
{
if (waitHandle.WaitOne(0))
{
if (_haveProcessId)
throw new InvalidOperationException(SR.Format(SR.ProcessHasExited, _processId.ToString(CultureInfo.CurrentCulture)));
else
throw new InvalidOperationException(SR.ProcessHasExitedNoId);
}
}
}
return _processHandle;
}
else
{
EnsureState(State.HaveId | State.IsLocal);
SafeProcessHandle handle = SafeProcessHandle.InvalidHandle;
handle = ProcessManager.OpenProcess(_processId, access, throwIfExited);
if (throwIfExited && (access & Interop.mincore.ProcessOptions.PROCESS_QUERY_INFORMATION) != 0)
{
if (Interop.mincore.GetExitCodeProcess(handle, out _exitCode) && _exitCode != Interop.mincore.HandleOptions.STILL_ACTIVE)
{
throw new InvalidOperationException(SR.Format(SR.ProcessHasExited, _processId.ToString(CultureInfo.CurrentCulture)));
}
}
return handle;
}
}
示例11: StopApp
// 10/28/2008 Log application stop so that we can track when IIS7 recycles the app.
public static void StopApp(HttpContext Context)
{
try
{
Guid gUSER_ID = Guid.Empty;
string sUSER_NAME = String.Empty;
string sMACHINE = String.Empty;
string sASPNET_SESSIONID = String.Empty;
string sREMOTE_HOST = String.Empty;
string sSERVER_HOST = String.Empty;
string sTARGET = String.Empty;
string sRELATIVE_PATH = String.Empty;
string sPARAMETERS = String.Empty;
string sFILE_NAME = String.Empty;
string sMETHOD = String.Empty;
string sERROR_TYPE = "Warning";
string sMESSAGE = "Application stop.";
Int32 nLINE_NUMBER = 0;
try
{
// 09/17/2009 Azure does not support MachineName. Just ignore the error.
sMACHINE = System.Environment.MachineName;
}
catch
{
}
StackFrame stack = new StackTrace(true).GetFrame(0);
if ( stack != null )
{
sFILE_NAME = stack.GetFileName();
sMETHOD = stack.GetMethod().ToString();
nLINE_NUMBER = stack.GetFileLineNumber();
}
try
{
DbProviderFactory dbf = DbProviderFactories.GetFactory(Context.Application);
using ( IDbConnection con = dbf.CreateConnection() )
{
con.Open();
// 10/07/2009 We need to create our own global transaction ID to support auditing and workflow on SQL Azure, PostgreSQL, Oracle, DB2 and MySQL.
using ( IDbTransaction trn = Sql.BeginTransaction(con) )
{
try
{
SqlProcs.spSYSTEM_LOG_InsertOnly(gUSER_ID, sUSER_NAME, sMACHINE, sASPNET_SESSIONID, sREMOTE_HOST, sSERVER_HOST, sTARGET, sRELATIVE_PATH, sPARAMETERS, sERROR_TYPE, sFILE_NAME, sMETHOD, nLINE_NUMBER, sMESSAGE, trn);
trn.Commit();
}
catch //(Exception ex)
{
trn.Rollback();
// 10/26/2008 Can't throw an exception here as it could create an endless loop.
//SplendidError.SystemMessage(Context, "Error", new StackTrace(true).GetFrame(0), Utils.ExpandException(ex));
}
}
if ( Sql.IsEffiProz(con) )
{
// 12/31/2010 Irantha. Shutdown command CheckPoints the database (remove the .log file and rewrite the .script file).
// If this is not done then the CheckPointing automatically happens when database is reopened next time.
// This would increase the next start-up time. Taoqi has auto shutdown set to false in connection string.
// So doing a Shutdown on APPLICATION_END event would reduce the next application start-up time.
using ( IDbCommand cmd = con.CreateCommand() )
{
cmd.CommandText = "SHUTDOWN";
cmd.ExecuteNonQuery();
}
}
}
}
catch
{
}
}
catch//(Exception ex)
{
//SplendidError.SystemMessage(Context, "Error", new StackTrace(true).GetFrame(0), ex);
//HttpContext.Current.Response.Write(ex.Message);
}
}
示例12: 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);
}
}
示例13: DebugLog
public void DebugLog(string Text, DebugLevel Level)
{
StackFrame x = new StackTrace(true).GetFrame(1);
string MethodName = x.GetMethod().Name;
string Filename = x.GetFileName();
int Line = x.GetFileLineNumber();
TDebugInfo db = new TDebugInfo()
{
Filename = Filename,
Level = Level,
Line = Line,
MethodName = MethodName,
Text = Text,
Time = DateTime.Now
};
if(DebugList.Count > DebugCount)
DebugList.RemoveAt(0);
DebugList.Add(db);
if (this.OnError != null)
{
OnError(this, new LogArgs() { DebugInfo = db });
}
}
示例14: winLogError
internal static RC winLogError(RC a, string b, string c)
{
var sf = new StackTrace(new StackFrame(true)).GetFrame(0); return winLogErrorAtLine(a, b, c, sf.GetFileLineNumber());
}
示例15: 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
{ }
}