/// <summary> /// String serialization of <see cref="TraceEventData" />. /// </summary> /// <returns>A string representing the <see cref="TraceEventData" /> instace.</returns> /// <remarks> /// To help visualization in basic TraceListener like the DefaultTraceListener (Visual Studio, DebugViewer). /// </remarks> public override string ToString() { if (TraceCategory == TraceCategory.Performance) { return(string.Format(CultureInfo.CurrentCulture, "{0}-{1}|{2}-{3}|{4}|{5}|{6}|{7}ms", TraceSourceType.ToString(), TraceSourceName, TraceEventType.ToString(), TraceEventName, TraceCategory, CreationDate, Message, ElapsedTime)); } if (TraceCategory == TraceCategory.Error || TraceCategory == TraceCategory.Warning && RawException != null) { return(string.Format(CultureInfo.CurrentCulture, "{0}-{1}|{2}-{3}|{4}|{5}|{6}|{7}|{8}|{9}", TraceSourceType.ToString(), TraceSourceName, TraceEventType.ToString(), TraceEventName, TraceCategory, CreationDate, Message, ExceptionType, RawException, StackTrace)); } return(string.Format(CultureInfo.CurrentCulture, "{0}-{1}|{2}-{3}|{4}|{5}|{6}", TraceSourceType.ToString(), TraceSourceName, TraceEventType.ToString(), TraceEventName, TraceCategory, CreationDate, Message)); }
internal static TransactionException Create(TraceSourceType traceSource, string message, Guid distributedTxId) { if (IncludeDistributedTxId(distributedTxId)) { return(new TransactionException(string.Format(SR.DistributedTxIDInTransactionException, message, distributedTxId))); } return(new TransactionException(message)); }
/// <summary> /// Creates the <see cref="IFrameworkTracer" /> corresponding to the specified traceSourceType with specified /// traceSourceName. /// </summary> /// <param name="traceSourceType">The trace source type.</param> /// <param name="traceSourceName">The instance name of the trace source type.</param> /// <returns> /// A <see cref="IFrameworkTracer" /> corresponding to specified parameter. /// </returns> /// <remarks> /// A new one is created if necessary. /// </remarks> public IFrameworkTracer CreateTracer(TraceSourceType traceSourceType, string traceSourceName) { if (string.IsNullOrEmpty(traceSourceName)) { throw new ArgumentNullException(nameof(traceSourceName)); } return(GetLoggerInternal(traceSourceType, traceSourceName)); }
internal static Exception CreateInvalidOperationException(TraceSourceType traceSource, string message, Exception innerException) { TransactionsEtwProvider etwLog = TransactionsEtwProvider.Log; if (etwLog.IsEnabled()) { etwLog.TransactionExceptionTrace(traceSource, TransactionExceptionType.InvalidOperationException, message, innerException==null?String.Empty:innerException.ToString()); } return new InvalidOperationException(message, innerException); }
/// <summary> /// Creates a trace source of the specified trace source type with the specified trace source name. /// </summary> /// <param name="traceSourceType">The trace source type.</param> /// <param name="traceSourceName">The instance name of the trace source type.</param> public void SetSource(TraceSourceType traceSourceType, string traceSourceName) { if (_traceSource != null) { return; } _traceSourceName = traceSourceName; _traceSourceType = traceSourceType; _traceSource = new TraceSource(traceSourceType.ToString()); }
internal static TransactionException Create(TraceSourceType traceSource, string?message, Exception?innerException) { TransactionsEtwProvider etwLog = TransactionsEtwProvider.Log; if (etwLog.IsEnabled()) { etwLog.TransactionExceptionTrace(TransactionExceptionType.TransactionException, message, innerException == null ? string.Empty : innerException.ToString()); } return(new TransactionException(message, innerException)); }
internal static Exception CreateInvalidOperationException(TraceSourceType traceSource, string message, Exception innerException) { TransactionsEtwProvider etwLog = TransactionsEtwProvider.Log; if (etwLog.IsEnabled()) { etwLog.TransactionExceptionTrace(traceSource, TransactionExceptionType.InvalidOperationException, message, innerException == null?String.Empty:innerException.ToString()); } return(new InvalidOperationException(message, innerException)); }
internal static new TransactionInDoubtException Create(TraceSourceType traceSource, string message, Exception innerException) { TransactionsEtwProvider etwLog = TransactionsEtwProvider.Log; if (etwLog.IsEnabled()) { etwLog.TransactionExceptionTrace(traceSource, TransactionExceptionType.TransactionInDoubtException, message, innerException.ToString()); } return(new TransactionInDoubtException(message, innerException)); }
internal static new TransactionInDoubtException Create(TraceSourceType traceSource, string message, Exception innerException, Guid distributedTxId) { string messagewithTxId = message; if (IncludeDistributedTxId(distributedTxId)) { messagewithTxId = string.Format(SR.DistributedTxIDInTransactionException, messagewithTxId, distributedTxId); } return(TransactionInDoubtException.Create(traceSource, messagewithTxId, innerException)); }
internal static Exception CreateInvalidOperationException(TraceSourceType traceSource, string?message, Exception?innerException, Guid distributedTxId) { string?messagewithTxId = message; if (IncludeDistributedTxId(distributedTxId)) { messagewithTxId = SR.Format(SR.DistributedTxIDInTransactionException, messagewithTxId, distributedTxId); } return(CreateInvalidOperationException(traceSource, messagewithTxId, innerException)); }
internal static TransactionException Create(TraceSourceType traceSource, string message, Exception innerException, Guid distributedTxId) { string messagewithTxId = message; if (IncludeDistributedTxId(distributedTxId)) { messagewithTxId = SR.DistributedTxIDInTransactionException(messagewithTxId, distributedTxId); } return(Create(traceSource, messagewithTxId, innerException)); }
/// <summary> /// Get the specified logger for the specified trace source. /// </summary> /// <param name="traceSourceType">The type of the source.</param> /// <param name="traceSourceName">The instance name of the source type.</param> /// <returns> /// The corresponding logger. /// </returns> private static TLogger GetLoggerInternal(TraceSourceType traceSourceType, string traceSourceName) { if (string.IsNullOrEmpty(traceSourceName)) { throw new ArgumentNullException(nameof(traceSourceName)); } string key = traceSourceType + "¤" + traceSourceName; if (!TracesSources.ContainsKey(key)) { TLogger newTraceSource = new TLogger(); newTraceSource.SetSource(traceSourceType, traceSourceName); TracesSources.Add(key, newTraceSource); } return(TracesSources[key]); }
internal void MethodExit(TraceSourceType traceSource, object thisOrContextObject, [CallerMemberName] string methodname = null) { if (IsEnabled(EventLevel.Verbose, ALL_KEYWORDS)) { if (traceSource == TraceSourceType.TraceSourceLtm) { MethodExitTraceLtm(IdOf(thisOrContextObject), methodname); } else if (traceSource == TraceSourceType.TraceSourceBase) { MethodExitTraceBase(IdOf(thisOrContextObject), methodname); } else if (traceSource == TraceSourceType.TraceSourceDistributed) { MethodExitTraceDistributed(IdOf(thisOrContextObject), methodname); } } }
internal void TransactionExceptionTrace(TraceSourceType traceSource, TransactionExceptionType type, string message, string innerExceptionStr) { if (IsEnabled(EventLevel.Error, ALL_KEYWORDS)) { if (traceSource == TraceSourceType.TraceSourceBase) { TransactionExceptionBase(type.ToString(), message, innerExceptionStr); } else { TransactionExceptionLtm(type.ToString(), message, innerExceptionStr); } } }
internal static new TransactionInDoubtException Create(TraceSourceType traceSource, string message, Exception innerException) { TransactionsEtwProvider etwLog = TransactionsEtwProvider.Log; if (etwLog.IsEnabled()) { etwLog.TransactionExceptionTrace(traceSource, TransactionExceptionType.TransactionInDoubtException, message, innerException.ToString()); } return new TransactionInDoubtException(message, innerException); }
/// <summary> /// Get the <see cref="IFrameworkTracer" /> corresponding to the specified traceSourceType. /// </summary> /// <param name="traceSourceType">The trace source type.</param> /// <returns> /// A <see cref="IFrameworkTracer" /> corresponding to specified parameter. /// </returns> /// <remarks> /// A new one is created if necessary. /// </remarks> public IFrameworkTracer GetFrameworkLogger(TraceSourceType traceSourceType) { string traceSourceName = GetType().Name; return(GetLoggerInternal(traceSourceType, traceSourceName)); }
internal static new TransactionInDoubtException Create(TraceSourceType traceSource, string message, Exception innerException, Guid distributedTxId) { string messagewithTxId = message; if (IncludeDistributedTxId(distributedTxId)) messagewithTxId = string.Format(SR.DistributedTxIDInTransactionException, messagewithTxId, distributedTxId); return TransactionInDoubtException.Create(traceSource, messagewithTxId, innerException); }
internal void MethodExit(TraceSourceType traceSource, [CallerMemberName] string methodname = null) { if (IsEnabled(EventLevel.Verbose, ALL_KEYWORDS)) { if (traceSource == TraceSourceType.TraceSourceLtm) { MethodExitTraceLtm(string.Empty, methodname); } else if (traceSource == TraceSourceType.TraceSourceBase) { MethodExitTraceBase(string.Empty, methodname); } else if (traceSource == TraceSourceType.TraceSourceDistributed) { MethodExitTraceDistributed(string.Empty, methodname); } } }
internal void ExceptionConsumed(TraceSourceType traceSource, Exception exception) { if (IsEnabled(EventLevel.Verbose, ALL_KEYWORDS)) { if (traceSource == TraceSourceType.TraceSourceBase) { ExceptionConsumedBase(exception.ToString()); } else { ExceptionConsumedLtm(exception.ToString()); } } }
internal static TransactionException Create(TraceSourceType traceSource, string message, Guid distributedTxId) { if (IncludeDistributedTxId(distributedTxId)) { return new TransactionException(string.Format(SR.DistributedTxIDInTransactionException, message, distributedTxId)); } return new TransactionException(message); }