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, }); } }
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)); } } }
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(); }