public static TracePayload GetSerializedPayload(object source, TraceRecord traceRecord, Exception exception, bool getServiceReference) { string eventSource = null; string extendedData = null; string serializedException = null; if (source != null) { eventSource = CreateSourceString(source); } if (traceRecord != null) { StringBuilder sb = new StringBuilder(); XmlTextWriter writer = new XmlTextWriter(new StringWriter(sb, CultureInfo.CurrentCulture)); writer.WriteStartElement(DiagnosticStrings.ExtendedDataTag); traceRecord.WriteTo(writer); writer.WriteEndElement(); extendedData = sb.ToString(); } if (exception != null) { serializedException = DiagnosticTrace.ExceptionToTraceString(exception); } if (getServiceReference && (DiagnosticTrace.traceAnnotation != null)) { return(new TracePayload(serializedException, eventSource, DiagnosticTrace.appDomainFriendlyName, extendedData, DiagnosticTrace.traceAnnotation())); } return(new TracePayload(serializedException, eventSource, DiagnosticTrace.appDomainFriendlyName, extendedData, string.Empty)); }
public void TraceTransfer(Guid newId) { Guid oldId = DiagnosticTrace.ActivityId; if (newId != oldId) { try { if (this.HaveListeners) { this.TraceSource.TraceTransfer(0, null, newId); } //also emit to ETW if (this.IsEtwEventEnabled(ref DiagnosticTrace.transferEventDescriptor)) { this.etwProvider.WriteTransferEvent(ref DiagnosticTrace.transferEventDescriptor, newId, DiagnosticTrace.traceAnnotation == null ? string.Empty : DiagnosticTrace.traceAnnotation(), DiagnosticTrace.appDomainFriendlyName); } } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } LogTraceFailure(null, e); } } }