Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        /// <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);
            }
        }
Ejemplo n.º 3
0
 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);
         }
     }
 }
Ejemplo n.º 4
0
 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));
         }
     }
 }