示例#1
0
 public override void WriteLogEvent(ILogger logger, LogEventBase logEvent)
 {
     if (OnItemLogged != null)
       {
     OnItemLogged(logEvent);
       }
 }
示例#2
0
 /// <summary>
 /// Output a log event to trace targets
 /// </summary>
 /// <param name="logEvent"></param>
 /// <returns></returns>
 public override void WriteLogEvent(ILogger logger, LogEventBase logEvent)
 {
     #if(DEBUG)
       Debug.WriteLine(logEvent.ToString());
     #else
       Trace.WriteLine(logEvent.ToString());
     #endif
 }
示例#3
0
 public void EnqueueLogEvent(LogEventBase logEvent)
 {
     lock (locker)
       {
     logEvents.Enqueue(logEvent);
     Monitor.PulseAll(locker);
       }
 }
示例#4
0
        public override void WriteLogEvent(ILogger logger, LogEventBase logEvent)
        {
            if (MsgOnly)
              {
            Console.WriteLine(logEvent.Message);
            return;
              }

              Console.WriteLine(logEvent.ToString());
        }
示例#5
0
        public virtual void PrepareInsertCommand(LogEventBase logEvent, ref SqlCommand cmd)
        {
            // TODO. Should not be required
              LogEvent evt = logEvent as LogEvent;

              cmd.Parameters.Add(new SqlParameter("@dateLogged", evt.Occurred));
              cmd.Parameters.Add(new SqlParameter("@severity", evt.LogEventLevel));
              cmd.Parameters.Add(new SqlParameter("@location", evt.Location));
              cmd.Parameters.Add(new SqlParameter("@message", evt.Message));
              cmd.Parameters.Add(new SqlParameter("@data", evt.ExceptionFormatted));
        }
示例#6
0
        public override void WriteLogEvent(ILogger logger, LogEventBase logEvent)
        {
            using (SqlConnection conn = new SqlConnection(connectionString))
              {
            conn.Open();

            SqlCommand cmd = new SqlCommand(insertStatement, conn);
            PrepareInsertCommand(logEvent, ref cmd);

            cmd.ExecuteNonQuery();

            conn.Close();
              }
        }
示例#7
0
 public virtual void WriteLogEvent(ILogger logger, LogEventBase logEvent)
 {
     // Commented exception as the AppenderBase will be called when parent logger is not null.
       throw new NotImplementedException();
 }
示例#8
0
 public override void WriteLogEvent(ILogger logger, LogEventBase logEvent)
 {
     logEventBuffer.Add(logEvent.ToString());
 }
示例#9
0
文件: Logger.cs 项目: salty/SmplLog
        /// <summary>
        /// Pass the logevent to all attached appenders
        /// </summary>
        /// <param name="logEvent"></param>
        private void DoAppend(LogEventBase logEvent)
        {
            //foreach (IAppender appender in appenders)
              //{
              //  // TODO - better for perf, is the appender is invalid, remove from the appenders for the logger
              //  if (appender.IsValid)
              //    appender.WriteLogEvent(this, logEvent);
              //}

              logEvent.logger = this;
              loggingEventQueue.EnqueueLogEvent(logEvent);
        }
示例#10
0
 void CallbackAppenderTests_OnItemLogged(LogEventBase logEvent)
 {
     called = true;
 }
示例#11
0
        public override void WriteLogEvent(ILogger logger, LogEventBase logEvent)
        {
            EventLogEntryType eventLogEntryType;

              switch(logger.LoggerEventLevel)
              {
            case EventLevel.Debug:
            case EventLevel.Info:
              eventLogEntryType = EventLogEntryType.Information;
              break;

            case EventLevel.Error:
            case EventLevel.Warn:
            case EventLevel.Fatal:
              eventLogEntryType = EventLogEntryType.Error;
              break;

            default:
              eventLogEntryType = EventLogEntryType.Information;
              break;
              }

              EventLog.WriteEntry(source, logEvent.ToString(), eventLogEntryType);
        }
示例#12
0
        public override void WriteLogEvent(ILogger logger, LogEventBase logEvent)
        {
            try
              {
            MailAddressCollection mac = new MailAddressCollection();
            mac.Add(new MailAddress(toAddress));

            MailMessage msg = new MailMessage(fromAddress, toAddress, subject, logEvent.ToString());
            mailSent = false;
            client.SendAsync(msg, failCount);

            //msg.BodyEncoding =
            //msg.BodyFormat = isHtml ? MailFormat.Html : MailFormat.Text;
            //msg.Priority =
            //msg.Bcc
            //msg.Cc =
            //msg.Attachments =
            //msg.DeliveryNotificationOptions = DeliveryNotificationOptions.
              }
              catch (Exception ex)
              {
            LogManager.LogInternalEvent(EventLevel.Error,
              string.Format("SMTP appender {0} failed to send", this.Name), ex);

            base.IncrementFailCount();
              }
        }
示例#13
0
        /// <summary>
        /// Log the event to the output file specified by the filePath parameter
        /// </summary>
        /// <param name="logEvent"></param>
        /// <returns></returns>
        /// <remarks>Exceptions propogate up the the Logger instance</remarks>
        public override void WriteLogEvent(ILogger logger, LogEventBase logEvent)
        {
            try
              {
            #if (DEBUG)
              LogManager.LogInternalEvent(EventLevel.Debug,
            string.Format("Thread {2}: Appender {0} attempting to write to file {1}", this.Name, this.filePath, Thread.CurrentThread.GetHashCode()), null);
            #endif

            // If max file size is set, check the current file size and rollover to a new file if necessary
            if (maxFileSize != NO_MAX_FILE_SIZE)
            {
              RolloverIfFileSizeExceeded();
            }

            StreamWriter.WriteLine(logEvent.ToString());
            StreamWriter.Flush();

              }
              catch (Exception ex)
              {
            LogManager.LogInternalEvent(EventLevel.Fatal, string.Format("Could not create the file logger for the path ", filePath), ex);
            IncrementFailCount();
              }
        }