private static string Convert(LoggingBoundaries lp) { switch (lp) { case LoggingBoundaries.UI: return(_ui); case LoggingBoundaries.UICritical: return(_uiCritical); case LoggingBoundaries.ServiceBoundary: return(_serviceBoundary); case LoggingBoundaries.DomainLayer: return(_domainLayer); case LoggingBoundaries.DataLayer: return(_dataLayer); case LoggingBoundaries.Database: return(_database); case LoggingBoundaries.Host: return(_host); default: return("Unknown"); } }
/// <summary> /// Logs string trace message to the log class /// </summary> public static bool LogTrace(LoggingBoundaries boundary, params object[] parameterValues) { if (!_logger.IsEnabled(LogLevel.Trace)) { return(false); } return(Log(LogMessage.LogTrace(boundary, parameterValues))); }
public static IDisposable CreateTrace(LoggingBoundaries boundary, params object[] parameterValues) { if (!_logger.IsEnabled(LogLevel.Trace)) { return(_dummyTrace); } return(new PerformanceTracer(boundary, parameterValues)); }
public LogMessage(LoggingBoundaries boundary, LogLevel entryType, params object[] parameterValues) : this() { Boundary = boundary; Level = entryType; var ofs = 0; if (parameterValues.Length > 0 && parameterValues[0] is string) { ofs++; Message = parameterValues[0].ToString(); } for (int i = ofs; i < parameterValues.Length; i++) { if (parameterValues[i] is Dictionary <string, object> ) { var ext = (Dictionary <string, object>)parameterValues[0]; Extended = ext; continue; } if (parameterValues[i] is Exception) { var e = (Exception)parameterValues[i]; Exception = e; Message = (string.IsNullOrEmpty(Message) ? string.Empty : Message + "\n") + ExpandException(e); if (parameterValues.Length - 1 > i) { Message = "{" + (i + 1) + "}\n" + Message; } if (Extended == null) { Extended = new Dictionary <string, object>(); } Extended["StackTrace"] = e.StackTrace; EventId = e.GetReferenceID().ToString(); continue; } if (string.IsNullOrEmpty(Message)) { Message = "{0}"; } if (parameterValues[i].GetType().IsPrimitive || parameterValues[i] is string) { Message = Message.Replace("{" + (i - ofs) + "}", parameterValues[i].ToString()); } else { Message = Message.Replace("{" + (i - ofs) + "}", JsonConvert.SerializeObject(parameterValues[i])); } } }
/// <summary> /// Log event for recording warning messages /// </summary> public static LogMessage LogWarning(LoggingBoundaries boundary, params object[] parameterValues) { try { if (parameterValues.Length == 0) { throw new Exception("must provide at least one parameter"); } return(new LogMessage(boundary, LogLevel.Warning, parameterValues)); } // ReSharper disable once EmptyGeneralCatchClause catch (Exception ex) { return(new LogMessage(boundary, LogLevel.Critical, "Failed to create log message\n{0}", ex.Message)); } }
public PerformanceTracer(LoggingBoundaries boundary, params object[] parameterValues) { _boundary = boundary; string operation = "Unknown"; if (parameterValues.Length > 0 && parameterValues[0] is string) { operation = parameterValues[0].ToString(); } if (parameterValues.Length > 0 && parameterValues[0] is Type) { operation = ((Type)parameterValues[0]).Name; } for (var i = 1; i < parameterValues.Length; i++) { if (parameterValues[i] is Type) { operation += "." + ((Type)parameterValues[i]).Name; } else { operation += "." + Convert.ToString(parameterValues[i]); } } _operation = operation; if (checkTracingAvailable()) { if (getActivityID().Equals(Guid.Empty)) { setActivityID(Guid.NewGuid()); } initialize(operation); } }
/// <summary> /// Logs exception and determines if exception should be thrown again /// </summary> /// <param name="boundary">the boundary layer that produced the message</param> /// <param name="ex">The exception thrown</param> /// <returns>true if the calling method should throw the exception again</returns> public static bool HandleException(LoggingBoundaries boundary, Exception ex) { LogError(boundary, ex); return(true); }
/// <summary> /// Log event for recording warning messages /// </summary> public static bool LogWarning(LoggingBoundaries boundary, params object[] parameterValues) { return(Log(LogMessage.LogWarning(boundary, parameterValues))); }
public void LogAudit(LoggingBoundaries boundary, string format, params object[] paramList) { Log.DebugFormat(paramList.Length == 0 ? format : string.Format(format, paramList), Convert(boundary), "Audit"); }
public void LogError(LoggingBoundaries boundary, string format, params object[] paramList) { Log.ErrorFormat(paramList.Length == 0 ? format : string.Format(format, paramList), Convert(boundary), "Error"); }
public void LogInformation(LoggingBoundaries boundary, string format, params object[] paramList) { Log.InfoFormat(paramList.Length == 0 ? format : string.Format(format, paramList), Convert(boundary), "Information"); }
public void LogWarning(LoggingBoundaries boundary, string format, params object[] paramList) { Log.WarnFormat(paramList.Length == 0 ? format : string.Format(format, paramList), Convert(boundary), "Warning"); }
public bool HandleException(LoggingBoundaries boundary, Exception ex) { Log.Error(Convert(boundary), ex); return(true); }