コード例 #1
0
        private bool TerminateInternal(int timeoutMs, StateKind state, string action)
        {
            lock (myLock)
            {
                if (State == StateKind.Initialized)
                {
                    LogLog.Verbose(LogCategory, "Can't {1} '{0}', because it hasn't been started yet", Id, action);
                    CleanupInternal();
                    return(true);
                }

                if (State >= state)
                {
                    LogLog.Verbose(LogCategory, "Trying to {2} async processor '{0}' but it's in state '{1}'", Id, State, action);
                    return(true);
                }

                State = state;
                Monitor.Pulse(myLock);
            }

            var res = myAsyncProcessingThread.Join(timeoutMs);

            if (!res)
            {
                LogLog.Warn($"Async processor {Id} hasn't finished in ${timeoutMs} ms. Trying to abort thread.");
                LogLog.Catch(() => myAsyncProcessingThread.Abort());
            }

            CleanupInternal();
            return(res);
        }
コード例 #2
0
        public virtual void Log(LoggingLevel level, string message, Exception exception = null)
        {
            if (!IsEnabled(level))
            {
                return;
            }

            LogLog.Catch(() =>
            {
                var formatted = Format(level, message, exception);
                Handlers?.Invoke(new LeveledMessage(level, formatted));
            }
                         );
        }