/// <summary> /// Writes a trace event message to the trace listeners in the Listeners collection using the specified event type and event identifier. /// </summary> /// <param name="traceSource">The 'TraceSource' instance.</param> /// <param name="traceEventType">One of the enumeration values that specifies the event type of the trace data.</param> /// <param name="message">The informative message to write.</param> /// <param name="duration">The trace event duration.</param> /// <param name="status">One of the enumeration values that specifies the event status of the trace event.</param> /// <param name="exception">THe exception that to trace as part of the trace event.</param> /// <param name="data">The trace data.</param> /// <param name="methodName">The calling method where the log originated from</param> internal static void TraceEventInternal(this TraceSource traceSource, TraceEventType traceEventType, string message, TimeSpan duration, TraceStatus status, Exception exception, IEnumerable <KeyValuePair <string, object> > data, string methodName) { try { if (!TraceSourceExt.ShouldTrace(traceSource, traceEventType)) { return; } TraceEventEntry traceEventEntry = TraceEventEntryBuilder.IncludeEnvironmentData(new TraceEventEntry() { ApplicationName = traceSource.Name, EventData = TraceSourceExt.EventDataBuilder.CreateTraceEventData(exception, data), EventDuration = duration, EventKeys = TraceSourceExt.EventDataBuilder.CreateEventKeys(TraceSourceExt.GetKeys()), EventType = traceEventType.ToString(), Message = message, MethodName = methodName, Status = (int)status }); traceSource.TraceData(traceEventType, 0, (object)traceEventEntry); traceSource.Flush(); } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(string.Format("An error occurred while tracing. {0}", (object)ex.Message)); } }
public static TraceEventEntry IncludeEnvironmentData(TraceEventEntry traceEventEntry) { if (traceEventEntry == null) { return((TraceEventEntry)null); } TraceEventEntry traceEventEntry1 = traceEventEntry; string str1 = traceEventEntry1.EventId ?? TraceEventEntryBuilder.GetEventId(); traceEventEntry1.EventId = str1; traceEventEntry.EventDate = traceEventEntry.EventDate == new DateTime() ? DateTime.Now : traceEventEntry.EventDate; TraceEventEntry traceEventEntry2 = traceEventEntry; DateTimeOffset? nullable = new DateTimeOffset?(traceEventEntry2.EventDateTimeOffset ?? DateTimeOffset.Now); traceEventEntry2.EventDateTimeOffset = nullable; TraceEventEntry traceEventEntry3 = traceEventEntry; string str2 = traceEventEntry3.MachineName ?? Environment.MachineName; traceEventEntry3.MachineName = str2; TraceEventEntry traceEventEntry4 = traceEventEntry; string str3 = traceEventEntry4.MethodName ?? TraceEventEntryBuilder.GetSourceMethodName(traceEventEntry.MethodName); traceEventEntry4.MethodName = str3; TraceEventEntry traceEventEntry5 = traceEventEntry; string str4 = traceEventEntry5.Referrer ?? TraceEventEntryBuilder.GetClientIp(); traceEventEntry5.Referrer = str4; return(traceEventEntry); }
private static string GetClientIp() { return(TraceEventEntryBuilder.GetSafe <string>((Func <string>)(() => { return (string)null; })) ?? TraceEventEntryBuilder.GetSafe <string>((Func <string>)(() => { return (string)null; }))); }