/// <summary> /// 获取日志数据 /// </summary> /// <param name="logEventDataAsync"></param> /// <returns></returns> private LogEventData GetLoggingEventData(LogEventDataAsync logEventDataAsync) { LocationInfo locationInfo = new LocationInfo(logEventDataAsync.CallerStackBoundaryDeclaringType, logEventDataAsync.CallerStackTrace); LogEventData logData = new LogEventData { Message = logEventDataAsync.Message, Date = DateTime.Now, Level = logEventDataAsync.Level, LogSource = string.IsNullOrEmpty(logEventDataAsync.LogSource) ? locationInfo.ClassName : logEventDataAsync.LogSource, ClassName = locationInfo.ClassName, MethodName = locationInfo.MethodName, LineNumber = locationInfo.LineNumber, FileName = locationInfo.FileName, IP = "NA", Emails = logEventDataAsync.Emails, FullInfo = locationInfo.FullInfo }; return(logData); }
/// <summary> /// 写日志 /// </summary> /// <param name="message">日志信息</param> /// <param name="level">级别</param> /// <param name="emails">是否发送邮件,不为空则发送邮件,多个接收人用英文分号;隔开</param> private void WriterToTargets(string message, LogLevel level, string emails = null) { try { LogEventDataAsync leda = new LogEventDataAsync { LogSource = _logSource, Level = level.Name, CallerStackBoundaryDeclaringType = GetType(), //获取当前实例 CallerStackTrace = new StackTrace(true), //获取当前StackTrace Message = message, Emails = emails }; AsyncHelpers.StartAsyncTask(_logWriter.Writer, leda);//执行异步写日志 } catch { } }