/// <summary> /// Executes the callback when the given trace level is enabled. That allows when tracing is enabled /// complex string formatting only when needed. /// </summary> /// <param name="msgType">The message type which must match.</param> /// <param name="level">The trace level which must match.</param> /// <param name="type">TypeHandle of your class.</param> /// <param name="action">The delegate to execute when it does match.</param> /// <returns>true when the delegate was executed, false otherwise.</returns> public static bool Execute(MessageTypes msgType, Level level, TypeHashes type, Action action) { if (TracerConfig.Instance.IsEnabled(type, msgType, level)) { action(); return(true); } else { return(false); } }
/// <summary> /// Write an exception to the configured output device. /// </summary> /// <param name="level">Trace Level. 1 is the high level overview, 5 is for high volume detailed traces.</param> /// <param name="type">TypeHandle instance which identifies your class type. This instance should be a static instance of your type.</param> /// <param name="method">The method name of your current method.</param> /// <param name="ex">The excepton to trace.</param> public static void Error(Level level, TypeHashes type, string method, Exception ex) { if (ex == null) { throw new ArgumentNullException("ex"); } if (TracerConfig.Instance.IsEnabled(type, MessageTypes.Error, level)) { TraceMsg(MsgTypeError, GenerateTypeMethodName(type, method), DateTime.Now, "{0}", ex); } }
public virtual bool IsMatch(TypeHashes type, MessageTypes msgTypeFilter, Level level) { bool lret = ((level & myLevelFilter) != Level.None); if (lret) { bool areSameSize = (myFilterHashes.Length == type.myTypeHashes.Length); for (int i = 0; i < myFilterHashes.Length; i++) { if (myFilterHashes[i] == MATCHANY) { break; } if (i < type.myTypeHashes.Length) { // The current filter does not match exit // otherwise we compare the next round. if (myFilterHashes[i] != type.myTypeHashes[i]) { lret = false; break; } // We are still here when the last arry item matches // This is a full match if (i == myFilterHashes.Length - 1 && areSameSize) { break; } } else // the filter string is longer than the domain. That can never match { lret = false; break; } } } if (lret) { lret = (msgTypeFilter & myMsgTypeFilter) != MessageTypes.None; } // If no match try next filter if (Next != null && lret == false) { lret = Next.IsMatch(type, msgTypeFilter, level); } return(lret); }
/// <summary> /// Write an error trace to the configured output device. /// </summary> /// <param name="level">Trace Level. 1 is the high level overview, 5 is for high volume detailed traces.</param> /// <param name="type">TypeHandle instance which identifies your class type. This instance should be a static instance of your type.</param> /// <param name="method">The method name of your current method.</param> /// <param name="fmt">Trace message format string</param> /// <param name="args">Optional message format arguments.</param> public static void Error(Level level, TypeHashes type, string method, string fmt, params object[] args) { if (fmt == null) { throw new ArgumentNullException(fmt); } if (type == null) { throw new ArgumentNullException("type"); } if (TracerConfig.Instance.IsEnabled(type, MessageTypes.Error, level)) { TraceMsg(MsgTypeError, GenerateTypeMethodName(type, method), DateTime.Now, fmt, args); } }
internal bool IsEnabled(TypeHashes type, MessageTypes msgType, Level level) { if (myListeners == null || type == null) { return(false); } bool lret = myFilters.IsMatch(type, msgType, level); if (myNotFilters != null && lret == true) { lret = myNotFilters.IsMatch(type, msgType, level); } return(lret); }
/// <summary> /// Write an exception to the configured output device. /// </summary> /// <param name="level">Trace Level. 1 is the high level overview, 5 is for high volume detailed traces.</param> /// <param name="type">TypeHandle instance which identifies your class type. This instance should be a static instance of your type.</param> /// <param name="method">The method name of your current method.</param> /// <param name="ex">The exception to trace.</param> /// <param name="fmt">Message describing what the exception is about.</param> /// <param name="args">Optional format arguments for the description message string.</param> public static void Error(Level level, TypeHashes type, string method, Exception ex, string fmt, params object[] args) { if (ex == null) { throw new ArgumentNullException("ex"); } if (fmt == null) { throw new ArgumentNullException("fmt"); } if (type == null) { throw new ArgumentNullException("type"); } if (TracerConfig.Instance.IsEnabled(type, MessageTypes.Error, level)) { string traceMsg = FormatStringSafe(fmt, args); TraceMsg(MsgTypeError, GenerateTypeMethodName(type, method), DateTime.Now, "{0}{1}{2}", traceMsg, Environment.NewLine, ex); } }
/// <summary> /// Create a new Tracer which traces method enter and leave (on Dispose) /// </summary> /// <param name="level">Trace Level. 1 is the high level overview, 5 is for high volume detailed traces.</param> /// <param name="type">TypeHandle instance which identifies your class type. This instance should be a static instance of your type.</param> /// <param name="method">The method name of your current method.</param> public Tracer(Level level, TypeHashes type, string method) { if (type == null) { throw new ArgumentNullException("type"); } if (method == null) { throw new ArgumentNullException("method"); } myEnterTime = DateTime.MinValue; myMethod = method; myType = type; myLevel = level; myTypeMethodName = null; if (TracerConfig.Instance.IsEnabled(myType, MessageTypes.InOut, myLevel)) { myEnterTime = DateTime.Now; TraceMsg(MsgTypeIn, this.TypeMethodName, myEnterTime, null, null); } }
/// <summary> /// Create a new Tracer which traces method enter and leave (on Dispose) /// </summary> /// <param name="type">TypeHandle instance which identifies your class type. This instance should be a static instance of your type.</param> /// <param name="method">The method name of your current method.</param> public Tracer(TypeHashes type, string method) : this(Level.L1, type, method) { }
static string GenerateTypeMethodName(TypeHashes type, string method) { return(type.FullQualifiedTypeName + "." + method); }
public override bool IsMatch(TypeHashes type, MessageTypes msgTypeFilter, Level level) { return(true); }