示例#1
0
        private static void consumeQueue()
        {
            Log4NetAsyncQueueWrapper wrapper = null;

            while (_queue.TryDequeue(out wrapper))
            {
                processQueuedItem(wrapper, _queue.Count);
            }
        }
示例#2
0
        public static void Enqueue(LogLevel loglevel, EventId eventid, object tstate, Exception ex, Delegate formatter, Type tstatetype, string name = "!")
        {
            int countQueued = _queue.Count;

            if (checkCapacity(countQueued))
            {
                Log4NetAsyncQueueWrapper wrapper = new Log4NetAsyncQueueWrapper(loglevel, eventid, tstate, ex, formatter, tstatetype, getEnqueueData(name));
                _queue.Enqueue(wrapper);
                _eventThreadAction.Set();
            }
        }
示例#3
0
        private static void processQueuedItem(Log4NetAsyncQueueWrapper wrapper, int countQueued)
        {
            Type tType = wrapper.TStateType;
            var  t     = Convert.ChangeType(wrapper.TStateObject, tType);

            string msg = string.Format("DQ={0},EVT={1},", countQueued.ToString(_qSizeFormatter), wrapper.EventId.Id.ToString("D4"));

            msg += wrapper.EnqueueData;

            if (wrapper.FormatterFn != null)
            {
                msg += (string)wrapper.FormatterFn.DynamicInvoke(t, wrapper.Exception);
            }
            else
            {
                msg += t.ToString();
            }

            switch (wrapper.LogLevel)
            {
            case LogLevel.Debug:
            case LogLevel.Trace:
                _logger.Debug(msg, wrapper.Exception);
                break;

            case LogLevel.Information:
                _logger.Info(msg, wrapper.Exception);
                break;

            case LogLevel.Warning:
                _logger.Warn(msg, wrapper.Exception);
                break;

            case LogLevel.Error:
                _logger.Error(msg, wrapper.Exception);
                break;

            case LogLevel.Critical:
                _logger.Fatal(msg, wrapper.Exception);
                break;

            default:
                msg = $"[Unrecognised logLevel {wrapper.LogLevel}] " + msg;
                _logger.Info(msg, wrapper.Exception);
                break;
            }

            // Email
            if (wrapper.LogLevel >= EmailLogThreshold)
            {
                sendEmail(msg, wrapper.LogLevel);
            }
        }