private void RegisterDiagnosticTraceWriter(string logPath, string logNamePrefix) { ITraceWriter traceWriter = new DiagnosticLogTextWriter(logPath, logNamePrefix); lock (this.syncRoot) { try { if (this.MainTraceWriter != null) { this.MainTraceWriter.Close(); } TraceListener traceListener = traceWriter as TraceListener; foreach (IThreadSafeTracer current in this.Tracers) { current.AddTraceListener(traceListener); } this.MainTraceWriter = traceWriter; Tracer <TraceManager> .WriteInformation("New diagnostic trace writer registered.", new object[0]); } catch (Exception ex) { Tracer <TraceManager> .WriteError(ex, "Could not register diagnostic trace writer.", new object[0]); throw new InvalidOperationException("Could not register diagnostic trace writer.", ex); } } }
private void RegisterDiagnosticTraceWriter(string logPath, string logNamePrefix) { ITraceWriter traceWriter = new DiagnosticLogTextWriter(logPath, logNamePrefix); lock (this.syncRoot) { try { if (this.MainTraceWriter != null) { this.MainTraceWriter.Close(); } TraceListener traceListener = traceWriter as TraceListener; foreach (IThreadSafeTracer current in this.Tracers) { current.AddTraceListener(traceListener); } this.MainTraceWriter = traceWriter; Tracer<TraceManager>.WriteInformation("New diagnostic trace writer registered.", new object[0]); } catch (Exception ex) { Tracer<TraceManager>.WriteError(ex, "Could not register diagnostic trace writer.", new object[0]); throw new InvalidOperationException("Could not register diagnostic trace writer.", ex); } } }
private void TraceData(TraceEventCache eventCache, string source, TraceEventType eventType, int processId, string processName, int threadId, string threadName, string assemblyFileName, string messageText, string errorText) { string formatString = eventCache.DateTime.ToLocalTime().ToString("u", CultureInfo.InvariantCulture); StringBuilder stringBuilder = new StringBuilder(250); DiagnosticLogTextWriter.AppendField(stringBuilder, formatString, new object[0]); DiagnosticLogTextWriter.AppendField(stringBuilder, "{0} ({1})", new object[] { processId, processName }); if (threadName != null) { DiagnosticLogTextWriter.AppendField(stringBuilder, "0x{0:x8} ({1})", new object[] { threadId, threadName }); } else { DiagnosticLogTextWriter.AppendField(stringBuilder, "0x{0:x8}", new object[] { threadId }); } DiagnosticLogTextWriter.AppendField(stringBuilder, assemblyFileName, new object[0]); DiagnosticLogTextWriter.AppendField(stringBuilder, source, new object[0]); DiagnosticLogTextWriter.AppendField(stringBuilder, eventType); if (!string.IsNullOrEmpty(messageText)) { messageText = messageText.Replace("{", "{{").Replace("}", "}}"); } DiagnosticLogTextWriter.AppendField(stringBuilder, messageText); if (!string.IsNullOrEmpty(errorText)) { errorText = errorText.Replace("{", "{{").Replace("}", "}}"); } DiagnosticLogTextWriter.AppendField(stringBuilder, (errorText != null) ? ("<!CDATA[[" + errorText + "]]>") : string.Empty, new object[0]); lock (this.syncRoot) { if (base.Writer != null) { try { base.Writer.WriteLine(stringBuilder.ToString()); } catch (IOException) { } } } }