示例#1
0
 public void WriteLogEvent(ILogEvent logEvent)
 {
     if (logEvent.Level >= _minLogLevel)
     {
         lock ( _pooledLogEventQueueByMethodNameLock ) {
             var methodName = logEvent.CorrespondingType != null ? (logEvent.CorrespondingType.Name + "." + logEvent.Method) : logEvent.Method;
             if (_pooledLogEventQueueByMethodName.ContainsKey(methodName))
             {
                 _pooledLogEventQueueByMethodName[methodName].PoolLogEvent(logEvent, _incrementPoolingSeconds);
             }
             else
             {
                 SendLogEventEmail(logEvent);
                 _pooledLogEventQueueByMethodName[methodName] = new PooledLogEventQueue(logEvent, _initialPoolingSeconds);
                 Task.Factory.StartNew(obj => HandlePooledLogEventQueue(methodName), "AIMOPoolingEMailLogWriter(" + methodName + ")");
             }
         }
     }
 }
示例#2
0
        public void SendPooledLogEventEmail(PooledLogEventQueue pooledLogEventQueue)
        {
            var    pooledLogEvents = pooledLogEventQueue.GetPooledLogEvents();
            string message         = "Event Details\n\n";

            message += "Time:" + pooledLogEventQueue.FirstLogEventDateTime + " to " + pooledLogEventQueue.LastLogEventDateTime + "\n";
            message += "Level:" + pooledLogEvents.First().Level + "\n";
            message += "Class:" + pooledLogEvents.First().CorrespondingType + "\n";
            message += "Method:" + pooledLogEvents.First().Method + "\n";
            message += "Count:" + pooledLogEvents.Count() + "\n\n";
            var maxMessages = Math.Min(10, pooledLogEvents.Count());

            for (int i = 0; i < maxMessages; i++)
            {
                message += "Message" + i + ":" + pooledLogEvents[i].Message + "\n\n";
            }
            var systemEmail = new SystemEmail(to: _emailSenderConfiguration.AdministratorEmailAddresses, cc: null, subject: string.Format("[{0}]", pooledLogEvents.First().Level), body: message);

            _emailSender.SendSystemEmail(systemEmail);
        }