public static void TraceError(Exception ex, string message, bool reportIt = true, [CallerFilePath] string filePath = "", [CallerLineNumber] int lineNumber = 0, [CallerMemberNameAttribute] string method = "")
{
if (LogLevel > eTraceType.Error)
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 NETFX
try { Trace.WriteLine("Exception caught! 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, Path.GetFileName(filePath), method, lineNumber, message + " (" + ex.Message + ")")); } catch { }
#elif UNIVERSAL
try { Debug.WriteLine(String.Format("{0} ERROR {1} [{2}:{3}] :: {4}", DateTime.Now, Path.GetFileName(filePath), method, lineNumber, message + " (" + ex.Message + ")")); } catch { }
#endif
try { TraceLine?.Invoke(eTraceType.Error, String.Format("{0} ERROR {1} [{2}:{3}] :: {4}", DateTime.Now, Path.GetFileName(filePath), method, lineNumber, message + " (" + ex.Message + ")")); } catch { }
ex = ex.InnerException;
}
if (reportIt)
ThrowYIncident?.Invoke(failure);
}