public void Log(Transaction tx, LogLevel level, string format, params object[] args) { string componentName = GetCallerComponentName(); switch (Mode) { case LoggingMode.Generic: Trace.WriteMessageEvent(string.Format("[PID:{0}] [TX:{1}] [>{2}] {3}", Process.GetCurrentProcess().Id, GetTransactionId(tx), componentName, string.Format(format, args)), (byte)level, 0); break; case LoggingMode.Service: Trace.WriteMessageEvent(string.Format("[S:{0}] [P:{1}] [{2}:{3}] [TX:{4}] [>{5}] {6}", ServiceName, PartitionIdentifier, ReplicaLabel, ReplicaIdentifier, GetTransactionId(tx), componentName, string.Format(format, args)), (byte)level, 0); break; case LoggingMode.Host: Trace.WriteMessageEvent(string.Format("[HostName:{0}] [PID:{1}] [TX:{2}] [>{3}] {4}", ServiceName, Process.GetCurrentProcess().Id, GetTransactionId(tx), componentName, string.Format(format, args)), (byte)level, 0); break; } }
private static string GetTransactionId(Transaction tx) { return(tx.ToString().Split(':').First()); }
public void Log(Transaction tx, string message) { Log(tx, LogLevel.Information, message); }
public void Log(Transaction tx, string format, params object[] args) { Log(tx, LogLevel.Information, format, args); }
/// <summary> /// Utility routine that wraps the replication calls to avoid dealing with transient exceptions. /// </summary> public static async Task ReplicateOperationAsync( Transaction tx, long stateProviderId, string traceType, object operationContext, OperationData metaData, OperationData redo, OperationData undo, int retryStartDelayInMilliseconds = TimeoutHelper.DefaultRetryStartDelayInMilliseconds, int exponentialBackoffFactor = TimeoutHelper.DefaultExponentialBackoffFactor, int maxSingleDelayInMilliseconds = TimeoutHelper.DefaultMaxSingleDelayInMilliseconds, CancellationToken cancellationToken = default(CancellationToken), TimeSpan?timeout = null) { TimeSpan maxRetry = timeout ?? TimeoutHelper.DefaultReplicationTimeout; RetryHelper retryHelper = new RetryHelper( retryStartDelayInMilliseconds, exponentialBackoffFactor, maxSingleDelayInMilliseconds, (int)maxRetry.TotalMilliseconds); int retryCount = 0; while (true) { cancellationToken.ThrowIfCancellationRequested(); Exception ex; try { // Issue replication operation. tx.AddOperation(metaData, undo, redo, operationContext, stateProviderId); return; } catch (Exception e) { // Unwrap if necessary ex = e is AggregateException ? e.InnerException : e; if (!IsRetryableReplicationException(ex)) { // Trace the failure and re-throw the exception. // There might be serialization exceptions. // All non retryable exception should be thrown to the user. AppTrace.TraceSource.WriteExceptionAsWarning( string.Format("ReplicationHelper.ReplicateOperationAsync@{0}", traceType), ex, "non-retriable replication exception {0}", ex.GetType()); throw ex; } } Trace.Assert(ex != null, "exception cannot be null"); // Trace if a few retries have failed. retryCount++; if (4 == retryCount) { AppTrace.TraceSource.WriteWarning( string.Format("ReplicationHelper.ReplicateOperationAsync@{0}", traceType), "retry transaction={0}, ex={1}", tx.TransactionId, ex); retryCount = 0; } // Backoff and retry await retryHelper.ExponentialBackoffAsync(ex, cancellationToken).ConfigureAwait(false); } }