public static bool IsThrowAnyException(Action checkedAction, string operation = null) { try { checkedAction(); return(false); } catch (Exception ex) { CurrentLogger.Trace($"Operation {operation} with error {ex.Message}"); } return(true); }
/// <summary> /// log using trace log level /// </summary> /// <param name="ex"> the exception to be logged</param> /// <param name="logObjectsArr">array of objects to log their values for custom message user must override toSting() method</param> /// <param name="messageFormat">format of the message to be logged</param> /// <param name="messageParameters">the parameters to fill the message placeholders</param> public static void LogTrace(string messageFormat, object[] messageParameters = null , Exception ex = null, object[] logObjectsArr = null , [CallerMemberName] string callerInfo = "") { string finalMessage = CreateLogMessage(logObjectsArr, messageFormat, callerInfo, messageParameters); if (ex == null) { CurrentLogger.Trace(finalMessage); } else { CurrentLogger.Trace(ex, finalMessage); } }
private void InternalStop() { using (CurrentLogger.ScopedTrace($"{GetType()}.{MethodBase.GetCurrentMethod()}")) { var task = _workerTask; if (task == null) { return; } _workerTask = null; _cancelSource.Cancel(); using (new RAII(task.Dispose)) { CurrentLogger.Trace($"Начинаем ожидание окончания задачи {GetType().Name}"); task.Wait(_stopTimeout); } } }
public void WaitForStopNoThrow(TimeSpan?stopTimeout = null) { using (CurrentLogger.ScopedTrace($"{GetType()}.{MethodBase.GetCurrentMethod()}")) { lock (SyncRoot) { if (_disposed) { return; } ExceptionHelper.ExceptionCatcher(() => { var task = _workerTask; if (task == null) { return; } CurrentLogger.Trace($"Начинаем ожидание окончания задачи {GetType().Name} без её завершения "); task.Wait(stopTimeout ?? TimeSpanConstants.Infinite); }, where : nameof(LongRunningTask) + ":" + GetType() + "." + nameof(StopNoThrow)); } } }