/////////////////////////////////////////////////////////////////////// private static void ResetTracePriority() { lock (syncRoot) { defaultTracePriority = DefaultTracePriority; } }
/////////////////////////////////////////////////////////////////////// private static void ResetTracePriorities() { lock (syncRoot) { tracePriorities = DefaultTracePriorities; } }
/// <summary> /// Zapíše Warning /// </summary> /// <param name="priority"></param> /// <param name="type"></param> /// <param name="method"></param> /// <param name="result"></param> /// <param name="items"></param> public void Warning(TracePriority priority, string type, string method, string result, params string[] items) { if (App.TraceForPriority(priority)) { this._TraceWrite(null, LEVEL_WARNING, "", type, method, result, false, items); } }
/// <summary> /// Zapíše Informaci, ihned /// </summary> /// <param name="priority"></param> /// <param name="type"></param> /// <param name="method"></param> /// <param name="result"></param> /// <param name="items"></param> public void InfoNow(TracePriority priority, string type, string method, string result, params string[] items) { if (App.TraceForPriority(priority)) { this._TraceWrite(null, LEVEL_INFO, "", type, method, result, true, items); } }
/////////////////////////////////////////////////////////////////////// private static void SetTracePriority( TracePriority priority ) { lock (syncRoot) { defaultTracePriority = priority; } }
/// <summary> /// Returns true when specified priority is equal or higher than TracePriority, and request for write to trace has been performed. /// </summary> /// <param name="priority"></param> /// <returns></returns> public static bool TraceForPriority(TracePriority priority) { if (priority == Application.TracePriority.Priority0_None) { return(false); } if (priority == Application.TracePriority.Priority9_Allways) { return(true); } return((int)priority >= Instance.__TracePriorityInt); }
/////////////////////////////////////////////////////////////////////// public static bool HasFlags( TracePriority flags, TracePriority hasFlags, bool all ) { if (all) { return((flags & hasFlags) == hasFlags); } else { return((flags & hasFlags) != TracePriority.None); } }
/////////////////////////////////////////////////////////////////////// private static void AdjustTracePriorities( TracePriority priority, bool enabled ) { lock (syncRoot) /* TRANSACTIONAL */ { if (enabled) { tracePriorities |= priority; } else { tracePriorities &= ~priority; } } }
public static void DebugTrace( int?threadId, string message, string category, TracePriority priority ) { if (!IsTracePossible()) { return; } if (!IsTraceEnabled(priority)) /* HACK: *PERF* Bail. */ { return; } string traceFormat = GetTraceFormat(); if (traceFormat == null) { return; } bool traceDateTime; bool tracePriority; bool traceAppDomain; bool traceInterpreter; bool traceThreadId; bool traceMethod; GetTraceFormatFlags( out traceDateTime, out tracePriority, out traceAppDomain, out traceInterpreter, out traceThreadId, out traceMethod); string methodName = null; DebugTraceRaw(FormatOps.TraceOutput(traceFormat, traceDateTime ? (DateTime?)TimeOps.GetNow() : null, tracePriority ? (TracePriority?)priority : null, traceAppDomain ? AppDomainOps.GetCurrent() : null, traceInterpreter ? Interpreter.GetActive() : null, traceThreadId ? threadId : null, message, traceMethod, ref methodName), category, methodName, priority); }
public static void DebugTrace( string message, string category, TracePriority priority ) { if (!IsTracePossible()) { return; } if (!IsTraceEnabled(priority)) /* HACK: *PERF* Bail. */ { return; } DebugTrace( GlobalState.GetCurrentSystemThreadId(), message, category, priority); }
public static void DebugTrace( Exception exception, string category, TracePriority priority ) { if (!IsTracePossible()) { return; } if (!IsTraceEnabled(priority)) /* HACK: *PERF* Bail. */ { return; } DebugTrace( GlobalState.GetCurrentSystemThreadId(), FormatOps.TraceException(exception), category, priority); }
public static void DebugTrace( int?threadId, Exception exception, string category, TracePriority priority ) { if (!IsTracePossible()) { return; } if (!IsTraceEnabled(priority)) /* HACK: *PERF* Bail. */ { return; } DebugTrace( threadId, FormatOps.TraceException(exception), category, priority); }
/////////////////////////////////////////////////////////////////////// private static void DebugTraceRaw( string message, string category, string methodName, TracePriority priority ) { // // TODO: Redirect these writes to the active IHost, if any? // if (IsTraceEnabled(priority, category, methodName)) { try { DebugOps.TraceWrite(message, category); /* throw */ } catch { // do nothing. } } }
/////////////////////////////////////////////////////////////////////// // // HACK: This is part of a hack that solves a chicken-and-egg problem // with the diagnostic tracing method used by this library. We // allow tracing to be disabled via an environment variable // and/or the shell command line. Unfortunately, by the time we // disable tracing, many messages will have typically already // been written to the trace listeners. To prevent this noise // (that the user wishes to suppress), we internalize the check // (i.e. we do it from inside the core trace method itself) and // initialize this variable [once] with the result of checking // the environment variable. // private static bool IsTraceEnabled( TracePriority priority, params string[] categories ) { bool result; lock (syncRoot) /* TRANSACTIONAL */ { if (isTraceEnabled == null) { // // NOTE: Cannot use the GlobalConfiguration.GetValue // method at this point because that method may // call into the DebugTrace method (below), which // calls this method. // if (CommonOps.Environment.DoesVariableExist( EnvVars.NoTrace)) { isTraceEnabled = false; } else if (CommonOps.Environment.DoesVariableExist( EnvVars.Trace)) { isTraceEnabled = true; } else { isTraceEnabled = isTraceEnabledByDefault; } } // // NOTE: Determine if tracing is globally enabled or disabled. // result = (bool)isTraceEnabled; // // NOTE: If tracing has been globally disabled, do not bother // checking any categories. // if (result) { // // NOTE: The priority flags specified by the caller must // all be present in the configured trace priority // flags. // if (!FlagOps.HasFlags(tracePriorities, priority, true)) { result = false; } else { // // NOTE: If the caller specified a null category -OR- // there are no trace categories specifically // enabled (i.e. all trace categories are // allowed), always allow the message through. // if ((categories != null) && (categories.Length > 0) && (traceCategories != null) && (traceCategories.Count > 0)) { // // NOTE: At this point, at least one of the // specified trace categories, if any, // must exist in the dictionary and its // associated value must be non-zero; // otherwise, the trace message is not // allowed through. // bool found = false; foreach (string category in categories) { if (category == null) { continue; } int value; if (traceCategories.TryGetValue( category, out value) && (value != 0)) { found = true; break; } } if (!found) { result = false; } } } } } return(result); }
/// <summary> /// Otevře Scope (dá Begin), ihned, jehož Dispose zapíše párový End /// </summary> /// <param name="priority"></param> /// <param name="type"></param> /// <param name="method"></param> /// <param name="result"></param> /// <param name="items"></param> /// <returns></returns> public ITraceScope ScopeNow(TracePriority priority, string type, string method, string result, params string[] items) { bool isReal = App.TraceForPriority(priority); return(TraceScope.GetScope(this, true, isReal, type, method, result, items)); }