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 }); } }
/// <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; }
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(); }
/// <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 (Interop.Kernel32.ProcessWaitHandle waitHandle = new Interop.Kernel32.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); } } } } // If we dispose of our contained handle we'll be in a bad state. NetFX dealt with this // by doing a try..finally around every usage of GetProcessHandle and only disposed if // it wasn't our handle. return(new SafeProcessHandle(_processHandle.DangerousGetHandle(), ownsHandle: false)); } else { EnsureState(State.HaveId | State.IsLocal); SafeProcessHandle handle = SafeProcessHandle.InvalidHandle; handle = ProcessManager.OpenProcess(_processId, access, throwIfExited); if (throwIfExited && (access & Interop.Advapi32.ProcessOptions.PROCESS_QUERY_INFORMATION) != 0) { if (Interop.Kernel32.GetExitCodeProcess(handle, out _exitCode) && _exitCode != Interop.Kernel32.HandleOptions.STILL_ACTIVE) { throw new InvalidOperationException(SR.Format(SR.ProcessHasExited, _processId.ToString(CultureInfo.CurrentCulture))); } } return(handle); } }
// 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); } }
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); }
/// <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); } }
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); } }
private static void DoTrue(bool condition, string message) { if (Debug.isDebugBuild && !condition) { System.Diagnostics.StackFrame f = new System.Diagnostics.StackTrace(true).GetFrame(2); string new_message = "Assertion failed in " + f.GetMethod() + " (" + f.GetFileName() + ":" + f.GetFileLineNumber() + ")"; if (!string.IsNullOrEmpty(message)) { new_message += "\n" + message; } Debug.Assert(condition, new_message); HaltWhen(!condition); } }
internal void CheckError() { //return; #if DEBUG return;//TODO: var frame = new System.Diagnostics.StackTrace(true).GetFrame(1); ErrorCode code = ErrorCode.InvalidValue; ThreadingHelper.BlockOnUIThread(() => { code = GL.GetError(); if (code != ErrorCode.NoError) { string filename = frame.GetFileName(); int line = frame.GetFileLineNumber(); string method = frame.GetMethod().Name; Debug.WriteLine("[GL] " + filename + ":" + method + " - " + line.ToString() + ":" + code.ToString()); } }, true); #endif }
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); }
// 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); } }
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); }
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; }
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 }); } }
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 }); }
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); }
/// <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); }
//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 { } }
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; }
/// <summary> /// Gets the name of the source file that called this function /// </summary> /// <param name="depth"> stack depths of the function used. </param> /// <returns> </returns> public static string SourceFileName(int depth) { var sf = new StackTrace(true).GetFrame(depth + 1); return sf.GetFileName(); }
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 }
/// <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; } }
internal static RC CORRUPT_BKPT() { var sf = new StackTrace(new StackFrame(true)).GetFrame(0); LOG(RC.CANTOPEN, "database corruption at line {0} of [{1}]", sf.GetFileLineNumber(), sf.GetFileName()); return RC.CORRUPT; }