private void AddError(LogEvent e, Exception err) { if (err != null) { e.Errors.Add(new EventMessage { Message = err.Message, StackTrace = err.StackTrace }); err = err.InnerException; while (err != null) { e.Errors.Add(new EventMessage { Message = err.Message, StackTrace = err.StackTrace }); err = err.InnerException; } } }
protected override void Append(log4net.Core.LoggingEvent loggingEvent) { try { LogEvent le = new LogEvent(); le.ErrorTime =loggingEvent.TimeStamp.ToString("yyyy-MM-dd HH:mm:ss"); le.EventType = loggingEvent.Level.ToString(); le.Message = loggingEvent.RenderedMessage; le.AppName = AppName; le.ServerTag = ServerTag; le.ErrorType = loggingEvent.ExceptionObject != null ? loggingEvent.ExceptionObject.GetType().ToString() : "未知错误类型"; AddError(le, loggingEvent.ExceptionObject); Add(le); } catch (Exception e_) { LogLog.Error(declaringType, e_.Message); } }
private void Add(LogEvent item) { CreateTime(); lock (mEvents) { mEvents.Enqueue(item); if (mEvents.Count > MaxRecords) Upload(null); } }