Esempio n. 1
0
 /// <summary>
 /// Does nothing. Optionally it calculates the layout text but
 /// discards the results.
 /// </summary>
 /// <param name="logEvent">The logging event.</param>
 public override void Write(LogEventInfo logEvent)
 {
     if (_formatMessage)
     {
         CompiledLayout.GetFormattedMessage(logEvent);
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Checks whether log event should be logged or not.
 /// </summary>
 /// <param name="logEvent">Log event.</param>
 /// <returns>
 /// <see cref="FilterResult.Ignore"/> - if the log event should be ignored<br/>
 /// <see cref="FilterResult.Neutral"/> - if the filter doesn't want to decide<br/>
 /// <see cref="FilterResult.Log"/> - if the log event should be logged<br/>
 /// </returns>
 protected internal override FilterResult Check(LogEventInfo logEvent)
 {
     if (IgnoreCase)
     {
         if (CompiledLayout.GetFormattedMessage(logEvent).ToLower().IndexOf(Substring.ToLower()) < 0)
         {
             return(Result);
         }
         else
         {
             return(FilterResult.Neutral);
         }
     }
     else
     {
         if (CompiledLayout.GetFormattedMessage(logEvent).IndexOf(Substring) < 0)
         {
             return(Result);
         }
         else
         {
             return(FilterResult.Neutral);
         }
     }
 }
Esempio n. 3
0
 /// <summary>
 /// Does nothing. Optionally it calculates the layout text but
 /// discards the results.
 /// </summary>
 /// <param name="logEvent">The logging event.</param>
 protected internal override void Write(LogEventInfo logEvent)
 {
     if (_formatMessage)
     {
         CompiledLayout.GetFormattedMessage(logEvent);
     }
 }
Esempio n. 4
0
 /// <summary>
 /// Writes the specified logging event to the attached debugger.
 /// </summary>
 /// <param name="logEvent">The logging event.</param>
 protected internal override void Write(LogEventInfo logEvent)
 {
     if (Debugger.IsLogging())
     {
         Debugger.Log(logEvent.Level.Ordinal, logEvent.LoggerName, CompiledLayout.GetFormattedMessage(logEvent) + "\n");
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Log message to RichTextBox
        /// </summary>
        /// <param name="logEvent">The logging event.</param>
        protected internal override void Write(LogEventInfo logEvent)
        {
            RichTextBoxRowColoringRule matchingRule = null;

            foreach (RichTextBoxRowColoringRule rr in RowColoringRules)
            {
                if (rr.CheckCondition(logEvent))
                {
                    matchingRule = rr;
                    break;
                }
            }

            if (UseDefaultRowColoringRules && matchingRule == null)
            {
                foreach (RichTextBoxRowColoringRule rr in _defaultRichTextBoxRowColoringRules)
                {
                    if (rr.CheckCondition(logEvent))
                    {
                        matchingRule = rr;
                        break;
                    }
                }
            }

            if (matchingRule == null)
            {
                matchingRule = RichTextBoxRowColoringRule.Default;
            }

            string logMessage = CompiledLayout.GetFormattedMessage(logEvent);

            FindRichTextBoxAndSendTheMessage(logMessage, matchingRule);
        }
Esempio n. 6
0
 /// <summary>
 /// Sends the
 /// rendered logging event over the network optionally concatenating it with a newline character.
 /// </summary>
 /// <param name="logEvent">The logging event.</param>
 public override void Write(LogEventInfo logEvent)
 {
     lock (this)
     {
         var msg = CompiledLayout.GetFormattedMessage(logEvent);
         _stream.WriteLine(msg);
     }
 }
Esempio n. 7
0
        /// <summary>
        /// Renders an array logging events.
        /// </summary>
        /// <param name="events">Array of logging events.</param>
        protected internal override void Write(LogEventInfo[] events)
        {
            if (events == null)
            {
                return;
            }
            if (events.Length == 0)
            {
                return;
            }

            if (_from == null || _to == null || _subject == null)
            {
                return;
            }

            LogEventInfo lastEvent = events[events.Length - 1];
            string       bodyText;

            // unbuffered case, create a local buffer, append header, body and footer
            StringBuilder bodyBuffer = new StringBuilder();

            if (CompiledHeader != null)
            {
                bodyBuffer.Append(CompiledHeader.GetFormattedMessage(lastEvent));
                if (AddNewLines)
                {
                    bodyBuffer.Append("\n");
                }
            }
            for (int i = 0; i < events.Length; ++i)
            {
                bodyBuffer.Append(CompiledLayout.GetFormattedMessage(events[i]));
                if (AddNewLines)
                {
                    bodyBuffer.Append("\n");
                }
            }
            if (CompiledFooter != null)
            {
                bodyBuffer.Append(CompiledFooter.GetFormattedMessage(lastEvent));
                if (AddNewLines)
                {
                    bodyBuffer.Append("\n");
                }
            }

            bodyText = bodyBuffer.ToString();

            MailMessage msg = new MailMessage();

            SetupMailMessage(msg, lastEvent);
            msg.Body = bodyText;
            SendMessage(msg);
        }
Esempio n. 8
0
 /// <summary>
 /// Writes the specified logging event to the <see cref="System.Diagnostics.Trace"/> facility.
 /// If the log level is greater than or equal to <see cref="LogLevel.Error"/> it uses the
 /// <see cref="System.Diagnostics.Trace.Fail(String)"/> method, otherwise it uses
 /// <see cref="System.Diagnostics.Trace.Write(String)" /> method.
 /// </summary>
 /// <param name="logEvent">The logging event.</param>
 protected internal override void Write(LogEventInfo logEvent)
 {
     if (logEvent.Level >= LogLevel.Error)
     {
         Trace.Fail(CompiledLayout.GetFormattedMessage(logEvent));
     }
     else
     {
         Trace.WriteLine(CompiledLayout.GetFormattedMessage(logEvent));
     }
 }
Esempio n. 9
0
 /// <summary>
 /// Checks whether log event should be logged or not.
 /// </summary>
 /// <param name="logEvent">Log event.</param>
 /// <returns>
 /// <see cref="FilterResult.Ignore"/> - if the log event should be ignored<br/>
 /// <see cref="FilterResult.Neutral"/> - if the filter doesn't want to decide<br/>
 /// <see cref="FilterResult.Log"/> - if the log event should be logged<br/>
 /// </returns>
 protected internal override FilterResult Check(LogEventInfo logEvent)
 {
     if (0 == String.Compare(CompiledLayout.GetFormattedMessage(logEvent), CompareTo, IgnoreCase))
     {
         return(Result);
     }
     else
     {
         return(FilterResult.Neutral);
     }
 }
Esempio n. 10
0
        /// <summary>
        /// Gets the bytes to be written.
        /// </summary>
        /// <param name="logEvent">Log event</param>
        /// <returns>Byte array.</returns>
        protected virtual byte[] GetBytesToWrite(LogEventInfo logEvent)
        {
            string text;

            if (NewLine)
            {
                text = CompiledLayout.GetFormattedMessage(logEvent) + "\r\n";
            }
            else
            {
                text = CompiledLayout.GetFormattedMessage(logEvent);
            }

            return(_encoding.GetBytes(text));
        }
Esempio n. 11
0
 /// <summary>
 /// Outputs the rendered logging event through the <c>OutputDebugString()</c> Win32 API.
 /// </summary>
 /// <param name="logEvent">The logging event.</param>
 public override void Write(LogEventInfo logEvent)
 {
     ASPHelper.IResponse response = ASPHelper.GetResponseObject();
     if (response != null)
     {
         if (AddComments)
         {
             response.Write("<!-- " + CompiledLayout.GetFormattedMessage(logEvent) + "-->");
         }
         else
         {
             response.Write(CompiledLayout.GetFormattedMessage(logEvent));
         }
         Marshal.ReleaseComObject(response);
     }
 }
Esempio n. 12
0
        /// <summary>
        /// Writes the specified logging event to the event log.
        /// </summary>
        /// <param name="logEvent">The logging event.</param>
        public override void Write(LogEventInfo logEvent)
        {
            UpdateEventLogSource();
            if (!_operational)
            {
                return;
            }

            string message = CompiledLayout.GetFormattedMessage(logEvent);

            if (message.Length > 16384)
            {
                // limitation of EventLog API
                message = message.Substring(0, 16384);
            }

            EventLogEntryType entryType;

            if (logEvent.Level >= LogLevel.Error)
            {
                entryType = EventLogEntryType.Error;
            }
            else if (logEvent.Level >= LogLevel.Warn)
            {
                entryType = EventLogEntryType.Warning;
            }
            else
            {
                entryType = EventLogEntryType.Information;
            }

            int eventID = 0;

            if (_eventID != null)
            {
                eventID = Convert.ToInt32(_eventID.GetFormattedMessage(logEvent), CultureInfo.InvariantCulture);
            }

            short category = 0;

            if (_category != null)
            {
                category = Convert.ToInt16(_category.GetFormattedMessage(logEvent), CultureInfo.InvariantCulture);
            }

            EventLog.WriteEntry(_sourceName, message, entryType, eventID, category);
        }
Esempio n. 13
0
        /// <summary>
        /// Displays the message box with the array of rendered logs messages and caption specified in the Caption
        /// parameter.
        /// </summary>
        /// <param name="logEvents">The array of logging events.</param>
        protected internal override void Write(LogEventInfo[] logEvents)
        {
            if (logEvents.Length == 0)
            {
                return;
            }

            StringBuilder sb           = new StringBuilder();
            LogEventInfo  lastLogEvent = logEvents[logEvents.Length - 1];

            foreach (LogEventInfo ev in logEvents)
            {
                sb.Append(CompiledLayout.GetFormattedMessage(ev));
                sb.Append("\n");
            }

            MessageBox.Show(sb.ToString(), _caption.GetFormattedMessage(lastLogEvent));
        }
Esempio n. 14
0
        /// <summary>
        /// Writes the specified logging event to the ASP.NET Trace facility. Log entries
        /// can then be viewed by navigating to http://server/path/Trace.axd
        /// If the log level is greater than or equal to <see cref="LogLevel.Warn"/> it uses the
        /// <see cref="System.Web.TraceContext.Warn(String,String)"/> method, otherwise it uses
        /// <see cref="System.Web.TraceContext.Write(String,String)" /> method.
        /// </summary>
        /// <param name="logEvent">The logging event.</param>
        public override void Write(LogEventInfo logEvent)
        {
            HttpContext context = HttpContext.Current;

            if (context == null)
            {
                return;
            }

            if (logEvent.Level >= LogLevel.Warn)
            {
                context.Trace.Warn(logEvent.LoggerName, CompiledLayout.GetFormattedMessage(logEvent));
            }
            else
            {
                context.Trace.Write(logEvent.LoggerName, CompiledLayout.GetFormattedMessage(logEvent));
            }
        }
Esempio n. 15
0
        /// <summary>
        /// ログを出力します。
        /// </summary>
        protected override void Write(LogEventInfo logEvent)
        {
            // "Apr 16 10:55:22" などど出したいので、
            // ここでは米国カルチャを選択します。
            var culture  = CultureInfo.GetCultureInfo("en-US");
            var priority = GetSyslogSeverity(logEvent.Level);
            var machine  = this.machineLayout.GetFormattedMessage(logEvent);
            var sender   = this.senderLayout.GetFormattedMessage(logEvent);
            var body     = CompiledLayout.GetFormattedMessage(logEvent);

            var message = string.Format(
                "<{0}>{1} {2} {3}: {4}",
                CalcSyslogPriority(priority),
                logEvent.TimeStamp.ToString("MMM dd HH:mm:ss", culture),
                machine,
                sender,
                body);

            var buffer = Encoding.UTF8.GetBytes(message);

            SendMessage(buffer);
        }
Esempio n. 16
0
        /// <summary>
        /// Prepares a message to be sent to the message queue.
        /// </summary>
        /// <param name="logEvent">The log event to be used when calculating label and text to be written.</param>
        /// <returns>The message to be sent</returns>
        /// <remarks>
        /// You may override this method in inheriting classes
        /// to provide services like encryption or message
        /// authentication.
        /// </remarks>
        protected virtual Message PrepareMessage(LogEventInfo logEvent)
        {
            Message msg = new Message();

            if (_label != null)
            {
                msg.Label = _label.GetFormattedMessage(logEvent);
            }
            msg.Recoverable = _recoverableMessages;
            msg.Priority    = _messagePriority;

            if (_useXmlEncoding)
            {
                msg.Body = CompiledLayout.GetFormattedMessage(logEvent);
            }
            else
            {
                byte[] dataBytes = _encoding.GetBytes(CompiledLayout.GetFormattedMessage(logEvent));

                msg.BodyStream.Write(dataBytes, 0, dataBytes.Length);
            }
            return(msg);
        }
Esempio n. 17
0
        /// <summary>
        /// Log message to control
        /// </summary>
        /// <param name="logEvent">The logging event.</param>
        public override void Write(LogEventInfo logEvent)
        {
            string logMessage = CompiledLayout.GetFormattedMessage(logEvent);

            FindControlAndSendTheMessage(logMessage);
        }
Esempio n. 18
0
 /// <summary>
 /// Outputs the rendered logging event through the <c>OutputDebugString()</c> Win32 API.
 /// </summary>
 /// <param name="logEvent">The logging event.</param>
 public override void Write(LogEventInfo logEvent)
 {
     OutputDebugString(CompiledLayout.GetFormattedMessage(logEvent));
 }
Esempio n. 19
0
 /// <summary>
 /// Renders the logging event message and adds it to the internal ArrayList of log messages.
 /// </summary>
 /// <param name="logEvent">The logging event.</param>
 protected internal override void Write(LogEventInfo logEvent)
 {
     _logs.Add(CompiledLayout.GetFormattedMessage(logEvent));
 }
Esempio n. 20
0
 /// <summary>
 /// Increases the number of messages.
 /// </summary>
 /// <param name="logEvent">The logging event.</param>
 protected internal override void Write(LogEventInfo logEvent)
 {
     _counter++;
     _lastMessage = CompiledLayout.GetFormattedMessage(logEvent);
 }
Esempio n. 21
0
 /// <summary>
 /// Formats the log event for write.
 /// </summary>
 /// <param name="logEvent">The log event to be formatted.</param>
 /// <returns>A string representation of the log event.</returns>
 protected virtual string GetFormattedMessage(LogEventInfo logEvent)
 {
     return(CompiledLayout.GetFormattedMessage(logEvent));
 }
Esempio n. 22
0
        protected override void Write(LogEventInfo logEvent)
        {
            string logMessage = CompiledLayout.GetFormattedMessage(logEvent);

            SendTheMessageToRemoteHost(this.Host, logMessage);
        }
Esempio n. 23
0
 /// <summary>
 /// Writes the specified log event to the console highlighting entries
 /// and words based on a set of defined rules.
 /// </summary>
 /// <param name="logEvent">Log event.</param>
 protected internal override void Write(LogEventInfo logEvent)
 {
     Output(logEvent, CompiledLayout.GetFormattedMessage(logEvent));
 }
Esempio n. 24
0
 /// <summary>
 /// Renders the logging event message and adds it to the internal ArrayList of log messages.
 /// </summary>
 /// <param name="logEvent">The logging event.</param>
 public override void Write(LogEventInfo logEvent)
 {
     _logs.Add(CompiledLayout.GetFormattedMessage(logEvent));
 }
Esempio n. 25
0
 /// <summary>
 /// Displays the message box with the log message and caption specified in the Caption
 /// parameter.
 /// </summary>
 /// <param name="logEvent">The logging event.</param>
 protected internal override void Write(LogEventInfo logEvent)
 {
     MessageBox.Show(CompiledLayout.GetFormattedMessage(logEvent), _caption.GetFormattedMessage(logEvent));
 }
Esempio n. 26
0
        protected override void Write(LogEventInfo logEvent)
        {
            if (_endpoint == null)
            {
                try {
                    IPHostEntry entry = Dns.GetHostEntry(_host);
                    for (int i = 0; i < entry.AddressList.Length; i++)
                    {
                        if (entry.AddressList[i].AddressFamily == AddressFamily.InterNetwork)
                        {
                            _endpoint = new IPEndPoint(entry.AddressList[i], _port);
                            break;
                        }
                    }
                }
                catch {
                    _endpoint = null;
                }

                if (_endpoint == null)
                {
                    _endpoint = new IPEndPoint(IPAddress.Loopback, _port);
                }
            }

            int facility = (int)_facility;

            int level = (int)SyslogLevel.Debug;

            if (logEvent.Level == LogLevel.Info)
            {
                level = (int)SyslogLevel.Information;
            }
            else if (logEvent.Level == LogLevel.Warn)
            {
                level = (int)SyslogLevel.Warning;
            }
            else if (logEvent.Level == LogLevel.Error)
            {
                level = (int)SyslogLevel.Error;
            }
            else if (logEvent.Level == LogLevel.Fatal)
            {
                level = (int)SyslogLevel.Critical;
            }

            int priority = (facility * 8) + level;

            string time = null;

            if (logEvent.TimeStamp.Day < 10)
            {
                time = logEvent.TimeStamp.ToString("MMM  d HH:mm:ss");
            }
            else
            {
                time = logEvent.TimeStamp.ToString("MMM dd HH:mm:ss");
            }

            string message = String.Format("<{0}>{1} {2} {3}", priority, time, _identity, CompiledLayout.GetFormattedMessage(logEvent));

            byte[] buffer = Encoding.ASCII.GetBytes(message);

            try {
                _socket.SendTo(buffer, _endpoint);
            }
            catch {
            }
        }