Beispiel #1
0
 public void Dispose()
 {
     _watch.Stop();
     if (this._logSuccess || !this.Success)
     {
         DashTrace.TraceInformation(new TraceMessage
         {
             Operation = "Completed",
             Success   = this.Success,
             Duration  = _watch.ElapsedMilliseconds,
             Message   = this._operation,
         });
     }
 }
Beispiel #2
0
 public static async Task <T> DoActionAsync <T>(string operation,
                                                Func <Task <T> > action,
                                                Func <StorageException, T> storageExceptionHandler,
                                                bool rethrowAllOtherExceptions = true,
                                                bool?logSuccess = null)
 {
     using (var runner = OperationRunner.Start(operation))
     {
         try
         {
             return(await action());
         }
         catch (StorageException ex)
         {
             runner.Success = false;
             DashTrace.TraceWarning(new TraceMessage
             {
                 Operation    = "Storage Exception",
                 Message      = operation,
                 ErrorDetails = DashErrorInformation.Create(ex.RequestInformation.ExtendedErrorInformation),
             });
             return(storageExceptionHandler(ex));
         }
         catch (Exception ex)
         {
             runner.Success = false;
             DashTrace.TraceWarning(new TraceMessage
             {
                 Operation    = "General Exception",
                 Message      = operation,
                 ErrorDetails = new DashErrorInformation {
                     ErrorMessage = ex.ToString()
                 },
             });
             if (rethrowAllOtherExceptions)
             {
                 throw;
             }
             return(default(T));
         }
     }
 }
Beispiel #3
0
 protected OperationRunner(string operation, bool?logSuccess = null)
 {
     _operation = operation;
     if (logSuccess.HasValue)
     {
         _logSuccess = logSuccess.Value;
     }
     else
     {
         _logSuccess = DashConfiguration.LogNormalOperations;
     }
     if (_logSuccess)
     {
         DashTrace.TraceInformation(new TraceMessage
         {
             Operation = "Start",
             Message   = operation,
         });
     }
     this.Success = true;
     _watch       = Stopwatch.StartNew();
 }