public static void Assert(Exception ex, bool reportIt = true, [CallerFilePath] string filePath = "", [CallerLineNumber] int lineNumber = 0, [CallerMemberNameAttribute] string method = "") { if (LogLevel > eTraceType.Critical) { return; } var stack = ex?.StackTrace; var failure = new YIncident() { IsAssert = true }; failure.StackTrace = ex != null ? new StackTrace(ex, true) : null; while (ex != null) { failure.Messages.Add(ex.Message); ex = ex.InnerException; } var msg = "Assert failed: " + Environment.NewLine + string.Join(Environment.NewLine, failure.Messages) + Environment.NewLine + "StackTrace:" + stack; Debug.Assert(false, msg); TraceError(msg, filePath: filePath, lineNumber: lineNumber, method: method); if (reportIt) { ThrowYIncident?.Invoke(failure); } }
public static void Assert(string Error_Message, bool reportIt = true, bool StackTrace = true, [CallerFilePath] string filePath = "", [CallerLineNumber] int lineNumber = 0, [CallerMemberNameAttribute] string method = "") { if (LogLevel > eTraceType.Critical) { return; } var fileName = Path.GetFileName(filePath); var failure = new YIncident() { FilePath = filePath, FileName = fileName, LineNumber = lineNumber, Method = method, IsAssert = true }; #if NETFX failure.StackTrace = new StackTrace(true); #endif failure.Messages.Add(Error_Message); var msg = "Assert failed: " + Error_Message + Environment.NewLine + (StackTrace && failure.StackTrace != null ? "StackTrace:" + failure.StackTrace : ""); Debug.Assert(false, msg + Environment.NewLine); TraceError(msg, filePath: filePath, lineNumber: lineNumber, method: method); if (reportIt) { ThrowYIncident?.Invoke(failure); } }
public static void TraceErrorException(Exception ex, string message = null, bool reportIt = true, [CallerFilePath] string filePath = "", [CallerLineNumber] int lineNumber = 0, [CallerMemberNameAttribute] string method = "") { if (LogLevel > eTraceType.Critical) { return; } #if DEBUG try { var p = Path.GetFileName(filePath); } catch { Debug.Assert(false, "Invalid Log message"); }; #endif var fileName = Path.GetFileName(filePath); var failure = new YIncident() { FilePath = filePath, FileName = fileName, LineNumber = lineNumber, Method = method }; failure.StackTrace = new StackTrace(ex, true); if (message != null) { failure.Messages.Add(message); } #if NETFX try { Trace.WriteLine("Exception caught!" + (message == null ? "" : " Msg: " + message) + " Stack trace: " + ex.StackTrace + "" + Environment.NewLine); } catch { } #elif UNIVERSAL try { Debug.WriteLine("Exception caught! Stack trace: " + ex.StackTrace + "" + Environment.NewLine); } catch { } #endif try { TraceLine?.Invoke(eTraceType.Error, "Exception caught! Stack trace: " + ex.StackTrace + "" + Environment.NewLine); } catch { } while (ex != null) { failure.Messages.Add(ex.Message); #if NETFX try { Trace.WriteLine(String.Format("{0} ERROR {1} [{2}:{3}] :: {4}", DateTime.Now, fileName, method, lineNumber, "Exception : " + ex.Message + "" + Environment.NewLine)); } catch { } #elif UNIVERSAL Debug.WriteLine(String.Format("{0} ERROR {1} [{2}:{3}] :: {4}", DateTime.Now, fileName, method, lineNumber, "Exception : " + ex.Message + "" + Environment.NewLine)); #endif try { TraceLine?.Invoke(eTraceType.Error, String.Format("{0} ERROR {1} [{2}:{3}] :: {4}", DateTime.Now, fileName, method, lineNumber, "Exception : " + ex.Message + "" + Environment.NewLine)); } catch { } ex = ex.InnerException; } if (reportIt) { ThrowYIncident?.Invoke(failure); } }
public static void Assert(string Error_Message, bool reportIt = true, bool StackTrace = true, [CallerFilePath] string filePath = "", [CallerLineNumber] int lineNumber = 0, [CallerMemberNameAttribute] string method = "") { if (LogLevel > eTraceType.Critical) return; var fileName = Path.GetFileName(filePath); var failure = new YIncident() { FilePath = filePath, FileName = fileName, LineNumber = lineNumber, Method = method, IsAssert = true }; #if NETFX failure.StackTrace = new StackTrace(true); #endif failure.Messages.Add(Error_Message); var msg = "Assert failed: " + Error_Message + Environment.NewLine + (StackTrace && failure.StackTrace != null ? "StackTrace:" + failure.StackTrace : ""); Debug.Assert(false, msg + Environment.NewLine); TraceError(msg, filePath: filePath, lineNumber: lineNumber, method: method); if (reportIt) ThrowYIncident?.Invoke(failure); }
public static void Assert(Exception ex, bool reportIt = true, [CallerFilePath] string filePath = "", [CallerLineNumber] int lineNumber = 0, [CallerMemberNameAttribute] string method = "") { if (LogLevel > eTraceType.Critical) return; var stack = ex?.StackTrace; var failure = new YIncident() { IsAssert = true }; failure.StackTrace = ex != null ? new StackTrace(ex, true) : null; while (ex != null) { failure.Messages.Add(ex.Message); ex = ex.InnerException; } var msg = "Assert failed: " + Environment.NewLine + string.Join(Environment.NewLine, failure.Messages) + Environment.NewLine + "StackTrace:" + stack; Debug.Assert(false, msg); TraceError(msg, filePath: filePath, lineNumber: lineNumber, method: method); if (reportIt) ThrowYIncident?.Invoke(failure); }
public static void TraceErrorException(Exception ex, string message = null, bool reportIt = true, [CallerFilePath] string filePath = "", [CallerLineNumber] int lineNumber = 0, [CallerMemberNameAttribute] string method = "") { if (LogLevel > eTraceType.Critical) return; #if DEBUG try { var p = Path.GetFileName(filePath); } catch { Debug.Assert(false, "Invalid Log message"); }; #endif var fileName = Path.GetFileName(filePath); var failure = new YIncident() { FilePath = filePath, FileName = fileName, LineNumber = lineNumber, Method = method }; failure.StackTrace = new StackTrace(ex, true); if (message != null) failure.Messages.Add(message); #if NETFX try { Trace.WriteLine("Exception caught!" + (message == null ? "" : " Msg: " + message) + " Stack trace: " + ex.StackTrace + "" + Environment.NewLine); } catch { } #elif UNIVERSAL try { Debug.WriteLine("Exception caught! Stack trace: " + ex.StackTrace + "" + Environment.NewLine); } catch { } #endif try { TraceLine?.Invoke(eTraceType.Error, "Exception caught! Stack trace: " + ex.StackTrace + "" + Environment.NewLine); } catch { } while (ex != null) { failure.Messages.Add(ex.Message); #if NETFX try { Trace.WriteLine(String.Format("{0} ERROR {1} [{2}:{3}] :: {4}", DateTime.Now, fileName, method, lineNumber, "Exception : " + ex.Message + "" + Environment.NewLine)); } catch { } #elif UNIVERSAL Debug.WriteLine(String.Format("{0} ERROR {1} [{2}:{3}] :: {4}", DateTime.Now, fileName, method, lineNumber, "Exception : " + ex.Message + "" + Environment.NewLine)); #endif try { TraceLine?.Invoke(eTraceType.Error, String.Format("{0} ERROR {1} [{2}:{3}] :: {4}", DateTime.Now, fileName, method, lineNumber, "Exception : " + ex.Message + "" + Environment.NewLine)); } catch { } ex = ex.InnerException; } if (reportIt) ThrowYIncident?.Invoke(failure); }