private static Assembly GetAssembly() { var currentAssembly = Assembly.GetExecutingAssembly(); var callerAssemblies = new StackTrace().GetFrames() .Select(x => x.GetMethod().ReflectedType.Assembly).Distinct() .Where(x => x.GetReferencedAssemblies().Any(y => y.FullName == currentAssembly.FullName)); var initialAssembly = callerAssemblies.Last(); string sJobName = initialAssembly.GetName().Name; return initialAssembly; }
/// <summary> /// 日志写入 /// </summary> /// <param name="theRecordGrade">日志级别</param> /// <param name="msgHeader">日志消息头信息</param> /// <param name="exception">异常消息信息</param> /// <remarks>Version:1.1.3.0</remarks> public override void WriteLog(Int32 theRecordGrade, String msgHeader, Exception exception) { if (theRecordGrade < TXTLogFactory.GetLogGrade(LogConfig)) return; var stackFrames = new StackTrace(exception, true).GetFrames(); StackFrame stackFrame = null; if (stackFrames != null) stackFrame = stackFrames.Last(); var logrec = LogFormatter.FormatLogRecord(PrepareLogHeader(), PrepareLogBody("【" + msgHeader + "】" + exception.Message), stackFrame); if (logrec != null) { LogRecordList.Add(logrec); } }
/// <summary> /// 日志记录 /// </summary> /// <param name="theRecordGrade">日志级别</param> /// <param name="exception">异常信息</param> public override void WriteLog(Int32 theRecordGrade, Exception exception) { if (theRecordGrade < TXTLogFactory.GetLogGrade(LogConfig)) return; //**********VERSION 1.1.1.0 START**********// var stackFrames = new StackTrace(exception, true).GetFrames(); StackFrame stackFrame = null; if (stackFrames != null) stackFrame = stackFrames.Last(); //**********VERSION 1.1.1.0 END**********// var logrec = LogFormatter.FormatLogRecord(PrepareLogHeader(), PrepareLogBody(exception.Message), stackFrame); if (logrec != null) { LogRecordList.Add(logrec); } }