internal static void Exit(TraceSource traceSource, string msg) { if (!ValidateSettings(traceSource, TraceEventType.Information)) { return; } PrintLine(traceSource, TraceEventType.Verbose, 0, "Exiting " + msg); // Trace.CorrelationManager.StopLogicalOperation(); }
internal static void PrintInfo(TraceSource traceSource, string msg) { if (!ValidateSettings(traceSource, TraceEventType.Information)) { return; } PrintLine(traceSource, TraceEventType.Information, 0, msg); }
internal static void Exit(TraceSource traceSource, string obj, string method, object retObject) { if (!ValidateSettings(traceSource, TraceEventType.Information)) { return; } string retValue = ""; if (retObject != null) { retValue = GetObjectName(retObject) + "#" + Logging.HashString(retObject); } Exit(traceSource, obj, method, retValue); }
internal static void Exit(TraceSource traceSource, string obj, string method, string retValue) { if (!ValidateSettings(traceSource, TraceEventType.Information)) { return; } if (!string.IsNullOrEmpty(retValue)) { retValue = "\t-> " + retValue; } Exit(traceSource, obj + "::" + method + "() " + retValue); }
internal static void Exit(TraceSource traceSource, string msg) { }
internal static void Enter(TraceSource traceSource, string obj, string method, string param) { if (!ValidateSettings(traceSource, TraceEventType.Information)) { return; } Enter(traceSource, obj + "::" + method + "(" + param + ")"); }
private static bool GetUseProtocolTextSetting(TraceSource traceSource) { return(DefaultUseProtocolTextOnly); }
internal static void Dump(TraceSource traceSource, object obj, string method, IntPtr bufferPtr, int length) { if (!ValidateSettings(traceSource, TraceEventType.Verbose) || bufferPtr == IntPtr.Zero || length < 0) { return; } byte[] buffer = new byte[length]; Marshal.Copy(bufferPtr, buffer, 0, length); Dump(traceSource, obj, method, buffer, 0, length); }
internal static void PrintError(TraceSource traceSource, string msg) { }
internal static void PrintLine(TraceSource traceSource, TraceEventType eventType, int id, string msg) { traceSource.TraceEvent(eventType, id, ("[" + GetThreadId().ToString("d4", CultureInfo.InvariantCulture) + "] ") + msg); }
internal static void PrintWarning(TraceSource traceSource, string msg) { }
internal static void PrintInfo(TraceSource traceSource, string msg) { }
internal static void Exit(TraceSource traceSource, string msg, string parameters) { }
internal static void PrintInfo(TraceSource traceSource, object obj, string method, string param) { if (!ValidateSettings(traceSource, TraceEventType.Information)) { return; } PrintLine(traceSource, TraceEventType.Information, 0, GetObjectName(obj) + "#" + Logging.HashString(obj) + "::" + method + "(" + param + ")"); }
private static int GetMaxDumpSizeSetting(TraceSource traceSource) { return(DefaultMaxDumpSize); }
internal static void PrintError(TraceSource traceSource, string msg) { if (!ValidateSettings(traceSource, TraceEventType.Error)) { return; } PrintLine(traceSource, TraceEventType.Error, 0, msg); }
internal static void PrintLine(TraceSource traceSource, TraceEventType eventType, int id, string msg) { string logHeader = "[" + Environment.CurrentManagedThreadId.ToString("d4", CultureInfo.InvariantCulture) + "] "; traceSource.TraceEvent(eventType, id, logHeader + msg); }
internal static bool IsVerbose(TraceSource traceSource) { return(ValidateSettings(traceSource, TraceEventType.Verbose)); }
internal static void Enter(TraceSource traceSource, object obj, string method, object paramObject) { if (!ValidateSettings(traceSource, TraceEventType.Information)) { return; } Enter(traceSource, GetObjectName(obj) + "#" + Logging.HashString(obj), method, paramObject); }
internal static void Enter(TraceSource traceSource, object obj, string method, object paramObject) { }
internal static void Enter(TraceSource traceSource, string obj, string method, object paramObject) { if (!ValidateSettings(traceSource, TraceEventType.Information)) { return; } string paramObjectValue = ""; if (paramObject != null) { paramObjectValue = GetObjectName(paramObject) + "#" + Logging.HashString(paramObject); } Enter(traceSource, obj + "::" + method + "(" + paramObjectValue + ")"); }
internal static void Exit(TraceSource traceSource, object obj, string method, object retObject) { }
internal static void Exit(TraceSource traceSource, object obj, string method, string retValue) { if (!ValidateSettings(traceSource, TraceEventType.Information)) { return; } Exit(traceSource, GetObjectName(obj) + "#" + Logging.HashString(obj), method, retValue); }
internal static void PrintWarning(TraceSource traceSource, object obj, string method, string msg) { }
internal static void Exit(TraceSource traceSource, string method, string parameters) { if (!ValidateSettings(traceSource, TraceEventType.Information)) { return; } Exit(traceSource, method + "() " + parameters); }
private static bool GetUseProtocolTextSetting(TraceSource traceSource) { return DefaultUseProtocolTextOnly; }
internal static void Exception(TraceSource traceSource, object obj, string method, Exception e) { if (!ValidateSettings(traceSource, TraceEventType.Error)) { return; } string infoLine = SR.Format(SR.net_log_exception, GetObjectLogHash(obj), method, e.Message); if (!string.IsNullOrEmpty(e.StackTrace)) { infoLine += Environment.NewLine + e.StackTrace; } PrintLine(traceSource, TraceEventType.Error, 0, infoLine); }
private static int GetMaxDumpSizeSetting(TraceSource traceSource) { return DefaultMaxDumpSize; }
internal static void PrintInfo(TraceSource traceSource, object obj, string msg) { if (!ValidateSettings(traceSource, TraceEventType.Information)) { return; } PrintLine(traceSource, TraceEventType.Information, 0, GetObjectName(obj) + "#" + Logging.HashString(obj) + " - " + msg); }
// Sets up internal config settings for logging. private static void InitializeLogging() { lock (InternalSyncObject) { if (!s_loggingInitialized) { bool loggingEnabled = false; s_webTraceSource = new NclTraceSource(TraceSourceWebName); s_httpListenerTraceSource = new NclTraceSource(TraceSourceHttpListenerName); s_socketsTraceSource = new NclTraceSource(TraceSourceSocketsName); s_webSocketsTraceSource = new NclTraceSource(TraceSourceWebSocketsName); s_cacheTraceSource = new NclTraceSource(TraceSourceCacheName); s_traceSourceHttpName = new NclTraceSource(TraceSourceHttpName); if (GlobalLog.IsEnabled) { GlobalLog.Print("Initalizating tracing"); } try { loggingEnabled = (s_webTraceSource.Switch.ShouldTrace(TraceEventType.Critical) || s_httpListenerTraceSource.Switch.ShouldTrace(TraceEventType.Critical) || s_socketsTraceSource.Switch.ShouldTrace(TraceEventType.Critical) || s_webSocketsTraceSource.Switch.ShouldTrace(TraceEventType.Critical) || s_cacheTraceSource.Switch.ShouldTrace(TraceEventType.Critical) || s_traceSourceHttpName.Switch.ShouldTrace(TraceEventType.Critical)); } catch (SecurityException) { // These may throw if the caller does not have permission to hook up trace listeners. // We treat this case as though logging were disabled. Close(); loggingEnabled = false; } s_loggingEnabled = loggingEnabled; s_loggingInitialized = true; } } }
internal static void PrintWarning(TraceSource traceSource, string msg) { if (!ValidateSettings(traceSource, TraceEventType.Warning)) { return; } PrintLine(traceSource, TraceEventType.Warning, 0, msg); }
// Confirms logging is enabled, given current logging settings private static bool ValidateSettings(TraceSource traceSource, TraceEventType traceLevel) { if (!s_loggingEnabled) { return false; } if (!s_loggingInitialized) { InitializeLogging(); } if (traceSource == null || !traceSource.Switch.ShouldTrace(traceLevel)) { return false; } return true; }
internal static void PrintError(TraceSource traceSource, object obj, string method, string msg) { if (!ValidateSettings(traceSource, TraceEventType.Error)) { return; } PrintLine(traceSource, TraceEventType.Error, 0, GetObjectName(obj) + "#" + Logging.HashString(obj) + "::" + method + "() - " + msg); }
internal static void Associate(TraceSource traceSource, object objA, object objB) { if (!ValidateSettings(traceSource, TraceEventType.Information)) { return; } string lineA = GetObjectName(objA) + "#" + Logging.HashString(objA); string lineB = GetObjectName(objB) + "#" + Logging.HashString(objB); PrintLine(traceSource, TraceEventType.Information, 0, "Associating " + lineA + " with " + lineB); }
internal static bool IsVerbose(TraceSource traceSource) { return ValidateSettings(traceSource, TraceEventType.Verbose); }
internal static void Exception(TraceSource traceSource, object obj, string method, Exception e) { }
internal static void Dump(TraceSource traceSource, object obj, string method, byte[] buffer, int offset, int length) { if (!ValidateSettings(traceSource, TraceEventType.Verbose)) { return; } if (buffer == null) { PrintLine(traceSource, TraceEventType.Verbose, 0, "(null)"); return; } if (offset > buffer.Length) { PrintLine(traceSource, TraceEventType.Verbose, 0, "(offset out of range)"); return; } PrintLine(traceSource, TraceEventType.Verbose, 0, "Data from " + GetObjectName(obj) + "#" + Logging.HashString(obj) + "::" + method); int maxDumpSize = GetMaxDumpSizeSetting(traceSource); if (length > maxDumpSize) { PrintLine(traceSource, TraceEventType.Verbose, 0, "(printing " + maxDumpSize.ToString(NumberFormatInfo.InvariantInfo) + " out of " + length.ToString(NumberFormatInfo.InvariantInfo) + ")"); length = maxDumpSize; } if ((length < 0) || (length > buffer.Length - offset)) { length = buffer.Length - offset; } do { int n = Math.Min(length, 16); string disp = string.Format(CultureInfo.CurrentCulture, "{0:X8} : ", offset); for (int i = 0; i < n; ++i) { disp += string.Format(CultureInfo.CurrentCulture, "{0:X2}", buffer[offset + i]) + ((i == 7) ? '-' : ' '); } for (int i = n; i < 16; ++i) { disp += " "; } disp += ": "; for (int i = 0; i < n; ++i) { disp += ((buffer[offset + i] < 0x20) || (buffer[offset + i] > 0x7e)) ? '.' : (char)(buffer[offset + i]); } PrintLine(traceSource, TraceEventType.Verbose, 0, disp); offset += n; length -= n; } while (length > 0); }