public void Error() { var logEvent = new AppLogEvent(); logEvent.Level = LogLevel.Error; logEvent.LogDate = DateTime.Now; logEvent.ProviderName = "Advantech.iFS"; if (this.Request != null) { logEvent.User = this.Request.User; logEvent.Machine = this.Request.Machine; logEvent.RequestUrl = this.Request.Url; logEvent.AllXml = this.Request.Params; } if (this.Exception != null) { //get error code if (logEvent.Code != 0) { logEvent.Code = this.Exception.HResult; } else { logEvent.Code = this.Exception.HResult; } //read error messave if (!string.IsNullOrEmpty(this.Exception.Message)) { logEvent.Message = this.Exception.Message; } else { if (!string.IsNullOrEmpty(this.Exception.Message)) { logEvent.Message = this.Exception.Message; } if (!string.IsNullOrEmpty(this.Exception.InnerException.Message)) { logEvent.Message = string.Format("{0} ### {1}", logEvent.Message, this.Exception.InnerException.Message); } } //read stack trace logEvent.StackTrace = this.Exception.StackTrace; logEvent.Source = this.Exception.Source; } //insert into database this.UnitWork.AppLogEvent.Insert(logEvent); Save(); }
public void Warning(string message, string source = null) { var logEvent = new AppLogEvent(); logEvent.Level = LogLevel.Warning; logEvent.LogDate = DateTime.Now; logEvent.ProviderName = "Advantech.Europe"; logEvent.User = HttpContext.Current.User.Identity.Name; logEvent.Message = message; logEvent.Code = 708; logEvent.Source = source; if (this.Request != null) { logEvent.User = this.Request.User; logEvent.Machine = this.Request.Machine; logEvent.RequestUrl = this.Request.Url; logEvent.AllXml = this.Request.Params; } this.UnitWork.AppLogEvent.Insert(logEvent); Save(); }
public void Info(string message, string source = null, double duration = 0) { var logEvent = new AppLogEvent(); logEvent.Level = LogLevel.Info; logEvent.LogDate = DateTime.Now; logEvent.ProviderName = "Advantech.iFS"; logEvent.User = HttpContext.Current.User.Identity.Name; logEvent.Message = message; logEvent.Code = 808; logEvent.Source = source; logEvent.Duration = duration; if (this.Request != null) { logEvent.User = this.Request.User; logEvent.Machine = this.Request.Machine; logEvent.RequestUrl = this.Request.Url; logEvent.AllXml = this.Request.Params; } this.UnitWork.AppLogEvent.Insert(logEvent); Save(); }
public static AppLogEvent GetIfxEvent(this LogEvent logEvent, ITextFormatter formatter) { AppLogEvent curEvent = new AppLogEvent { TraceLevel = (uint)logEvent.Level, MessageTemplate = logEvent.MessageTemplate.Text, TrackId = GetProp(new List <string> { "track_id", "TrackId" }, logEvent.Properties), //YYYY-MM-DDThh:mm:ss[.f{1,7}]Z //OriginalTime = logEvent.Timestamp.ToString("YYYY-MM-DDThh:mm:ss.fffZ") OriginalTimeFromSerilog = logEvent.Timestamp.ToString() }; foreach (var token in logEvent.MessageTemplate.Tokens) { var complexToken = token as PropertyToken; if (complexToken != null) { var tokenObj = logEvent.Properties[complexToken.PropertyName] as DictionaryValue; if (tokenObj != null) { var dict = GetSimpleHashTable(tokenObj.Elements); long?tmp = GetLongProp(new List <string> { "ConsumerId", "UserId" }, dict); if (tmp != null) { curEvent.ConsumerId = tmp.Value; } tmp = GetLongProp(new List <string> { "MerchantId" }, dict); if (tmp != null) { curEvent.MerchantId = tmp.Value; } if (String.IsNullOrWhiteSpace(curEvent.TrackId)) { curEvent.TrackId = GetProp(new List <string> { "TrackId" }, dict); } curEvent.MsgType = GetProp(new List <string> { "Type" }, dict); curEvent.MsgSource = GetProp(new List <string> { "Source" }, dict); curEvent.MsgTarget = GetProp(new List <string> { "Target" }, dict); curEvent.MessageId = GetProp(new List <string> { "MessageId" }, dict); } } } using (var render = new StringWriter()) { formatter.Format(logEvent, render); curEvent.Message = render.ToString(); } return(curEvent); }