コード例 #1
0
        /// <see cref="AppenderSkeleton.Append(LoggingEvent)"/>
        protected override void Append(LoggingEvent loggingEvent)
        {
            // Render the logging event to a string.
            var rawMessage = RenderLoggingEvent(loggingEvent);
            var signal = new Signal()
            {
                Logger = "log4net",
                AppDomain = loggingEvent.Domain,
                Identity = loggingEvent.Identity,
                TimeStamp = loggingEvent.TimeStamp,
                LogLevel = loggingEvent.Level.DisplayName,
                LoggerName = loggingEvent.LoggerName,
                Message = loggingEvent.RenderedMessage,
                Exception = loggingEvent.ExceptionObject,
                RawMessage = rawMessage
            };

            // Send the log message to the web service.
            try
            {
                Send(JsonConvert.SerializeObject(signal), false);
            }
            catch (Exception e)
            {
                ErrorHandler.Error("An error occurred while connecting to the Cloudish logging service.", e);
            }

        }
コード例 #2
0
        /// <see cref="AppenderSkeleton.Append(LoggingEvent[])"/>
        protected override void Append(LoggingEvent[] loggingEvents)
        {
            // Prepare a StringBuilder to write the messages to.
            var logMessages = new StringBuilder();

            //TODO: In the future this will call bulk send
            // Render each logging event to a string, separating events with a new line.
            foreach (var logEvent in loggingEvents)
            {
                var rawMessage = RenderLoggingEvent(logEvent);
                var signal = new Signal()
                {
                    Logger = "log4net",
                    AppDomain = logEvent.Domain,
                    Identity = logEvent.Identity,
                    TimeStamp = logEvent.TimeStamp,
                    LogLevel = logEvent.Level.DisplayName,
                    LoggerName = logEvent.LoggerName,
                    Message = logEvent.RenderedMessage,
                    Exception = logEvent.ExceptionObject,
                    RawMessage = rawMessage
                };

                logMessages.Append(string.Concat(JsonConvert.SerializeObject(signal), "\n"));
            }

            // Send the log message to the web service.
            try
            {
                Send(logMessages.ToString(), true);
            }
            catch (Exception e)
            {
                ErrorHandler.Error("An error occurred while connecting to the Cloudish logging service while trying to bulk log.", e);
            }
        }