Exemplo n.º 1
0
        private static void ProcessLogEntryViaWriter()
        {
            LogEntry logEntry;

            while ((logEntry = LogEntryQueueManager.DeQueueForFileWriter()) != null)
            {
                LogEntryFileWriter.Write(logEntry);
            }
        }
Exemplo n.º 2
0
        public override void TraceData(System.Diagnostics.TraceEventCache eventCache, string source, System.Diagnostics.TraceEventType eventType, int id, object data)
        {
            var log = data as LogEntry;

            LogEntryFormatter.SetLogFormatter(log, this.Formatter);
            try
            {
                if (log != null && Formatter != null)
                {
                    log.TimeStamp = DateTime.Now;
                    if (ConfigurationManager.LoggingConfigurationManager.DatabaseLogSwitch)
                    {
                        //写入到数据库中
                        LogEntryQueueManager.EnQueueForDbWriter(log);
                    }

                    if (ConfigurationManager.LoggingConfigurationManager.FileLogSwitch)
                    {
                        LogEntryQueueManager.EnQueueForDbWriter(log);
                    }

                    //发送邮件
                    LogEntryQueueManager.EnQueueForEmailSender(log);
                }
                else
                {
                    base.TraceData(eventCache, source, eventType, id, data);
                }

                if (!ConfigurationManager.LoggingConfigurationManager.FileLogSwitch)
                {
                    return;
                }
                _logCount = (_logCount + 1) % _bufferSize;
                if (_logCount == 0)
                {
                    LogEventManager.NotifyWriterLog();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }