/// <summary> /// </summary> protected static String GetError(Exception ex, Error? error = null) { if (ex.IsNull()) return Format(error: error); if (!ex.InnerException.IsNull()) return Format(ex.InnerException.Message, error); return Format(ex.Message, error); }
public override ILOGGER Log(LEVEL level, string message, Exception ex = null) { return this.Fluently(_ => { var type = Mapping[level]; ex .IsNull() .IfTrue(() => Diagnostics.Log(type, message)) .IfFalse(() => Diagnostics.Log(type, ex, message)); ; }); }
static string SerializeException(Exception e, string exceptionMessage) { if (e.IsNull()) return string.Empty; exceptionMessage = "{0}{1}{2}\n{3}".FormatWith(exceptionMessage, exceptionMessage.IsEmpty() ? "" : "\n\n", e.Message, e.StackTrace); if (e.InnerException.IsNotNull()) exceptionMessage = SerializeException(e.InnerException, exceptionMessage); return exceptionMessage; }
public static void LogException(this ILogProvider provider, Exception exception) { var stackFrame = new StackFrame(1, true); var method = stackFrame.GetMethod(); string memberName = null; if (method.IsNotNull()) { memberName = method.Name; } var sourceFilePath = stackFrame.GetFileName(); var sourceLineNumber = stackFrame.GetFileLineNumber(); if (exception.IsNull()) { throw new ArgumentNullException("exception"); } InternalLogMessage(provider, exception.ToString(), Severity.Error, Verbosity.Normal, memberName, sourceFilePath, sourceLineNumber); }
public static void Shutdown(Exception eventArgs = null) { sUtilities.RemovePidFile(); sListener.Exit = true; Console.CursorVisible = true; if(!eventArgs.IsNull()) { Log.Error("Main", sLConsole.GetString("An unhandled exception has been thrown. ({0})"), eventArgs.Message); sCrashDumper.CreateCrashDump(eventArgs); } var packet = new SchumixPacket(); packet.Write<int>((int)Opcode.SMSG_CLOSE_CONNECTION); packet.Write<int>((int)0); sServerPacketHandler.SendPacketBackAllHost(packet); Thread.Sleep(2000); sRuntime.Exit(); }
/// <summary> /// 显示详细的出错信息 /// </summary> /// <param name="ex">Exception ex</param> /// <param name="offSet"></param> /// <param name="sb"></param> private static void _expandException(Exception ex, int offSet, StringBuilder sb) { if (ex.IsNull()) return; Type t = ex.GetType(); string paddingString = ""; if (offSet > 1) paddingString = new String(' ', offSet * 4); sb.AppendFormat("{0}Exception: {1}{2}", paddingString, t.Name, Environment.NewLine); sb.AppendFormat("{0}Message: {1}{2}", paddingString, ex.Message, Environment.NewLine); sb.AppendFormat("{0}Source: {1}{2}", paddingString, ex.Source, Environment.NewLine); if (ex.StackTrace.IsNotNull()) sb.AppendFormat("{0}Stack Trace: {1}{2}", paddingString, ex.StackTrace.Trim(), Environment.NewLine); if (ex.TargetSite.IsNotNull()) sb.AppendFormat("{0}Method: {1}{2}", paddingString, ex.TargetSite.Name, Environment.NewLine); sb.AppendFormat("{0}Native: {1}{2}", paddingString, ex.ToString(), Environment.NewLine); sb.AppendFormat("{0}Data: {1}{2}", paddingString, expandData(ex.Data, offSet), Environment.NewLine); //Exception baseException = ex.GetBaseException(); //if (baseException.IsNotNull()) sb.AppendFormat("{0}Base: {1}{2}", paddingString, ex.GetBaseException(), Environment.NewLine); _expandException(ex.InnerException, offSet + 1, sb); }
public void SetException(Exception exception) { if (exception.IsNull()) return; ; LastException = exception; MyCallstackItem.ExceptionMessage = exception.Message; MyCallstackItem.StackTrace = exception.StackTrace; }
public override ILogger Log(LogLevel level, string message, Exception ex = null) { return this.Fluently(() => Console.WriteLine(level + ":" + message + (ex.IsNull() ? String.Empty : ", exception: " + ex.ToString()))); }