コード例 #1
0
        /// <summary>
        /// First attemps to create a RollbarClient using config read from
        /// appSettings. Uses properties of this class as overrides if specified.
        /// </summary>
        /// <param name="logEvent"></param>
        /// <returns></returns>
        private RollbarClient CreateClient(LogEventInfo logEvent)
        {
            var configuration = new Configuration(AccessToken);

            if (!string.IsNullOrEmpty(Endpoint))
                configuration.Endpoint = Endpoint;

            if (Environment != null)
                configuration.Environment = Environment.Render(logEvent);

            if (Platform != null)
                configuration.Platform = Platform.Render(logEvent);

            if (Language != null)
                configuration.Language = Language.Render(logEvent);

            if (Framework != null)
                configuration.Framework = Framework.Render(logEvent);

            var client = new RollbarClient(configuration);
            client.RequestStarting += RollbarClientRequestStarting;
            client.RequestCompleted += RollbarClientRequestCompleted;

            return client;
        }
コード例 #2
0
        //public string Endpoint { get; set; }

        //public PatternLayout Environment { get; set; }

        //public PatternLayout Platform { get; set; }

        //public PatternLayout Language { get; set; }

        //public PatternLayout Framework { get; set; }

        #endregion

        #region Override implementation of AppenderSkeleton

        /// <summary>
        /// This method is called by the <see cref="M:AppenderSkeleton.DoAppend(LoggingEvent)"/> method.
        /// </summary>
        /// <param name="loggingEvent">The event to log.</param>
        /// <remarks>
        /// <para>
        /// Writes the event to Rollbar.
        /// </para>
        /// <para>
        /// The format of the output will depend on the appender's layout.
        /// </para>
        /// </remarks>
        override protected void Append(LoggingEvent loggingEvent)
        {
            var client = new RollbarClient(this.AccessToken);

            client.RequestStarting += this.RollbarClient_RequestStarting;
            client.RequestCompleted += this.RollbarClient_RequestCompleted;

            //if (!string.IsNullOrWhiteSpace(this.Endpoint))
            //    client.Configuration.Endpoint = this.Endpoint;

            //if (this.Environment != null)
            //    client.Configuration.Environment = this.Environment.Format(loggingEvent);

            //if (this.Platform != null)
            //    client.Configuration.Platform = this.Platform.Format(loggingEvent);

            //if (this.Language != null)
            //    client.Configuration.Language = this.Language.Format(loggingEvent);

            var notice = loggingEvent.ExceptionObject != null
                ? client.NoticeBuilder.CreateExceptionNotice(loggingEvent.ExceptionObject)
                : client.NoticeBuilder.CreateMessageNotice(base.RenderLoggingEvent(loggingEvent));

            notice.Level = ConvertLogLevel(loggingEvent.Level);
            //notice.Title = string.Empty;

            client.Send(notice);
        }
コード例 #3
0
        /// <summary>
        /// Sends the given event to Rollbar
        /// </summary>
        /// <param name="loggingEvent">The event to report</param>
        protected override void Append(LoggingEvent loggingEvent)
        {
            var client = new RollbarClient(_configuration);

            if (loggingEvent.Level >= Level.Critical)
            {
                Send(loggingEvent, client.SendCriticalMessage, client.SendCriticalException);
            }
            else if (loggingEvent.Level >= Level.Error)
            {
                Send(loggingEvent, client.SendErrorMessage, client.SendErrorException);
            }
            else if (loggingEvent.Level >= Level.Warn)
            {
                Send(loggingEvent, client.SendWarningMessage, client.SendWarningException);
            }
            else if (loggingEvent.Level >= Level.Info)
            {
                client.SendInfoMessage(loggingEvent.RenderedMessage);
            }
            else if (loggingEvent.Level >= Level.Debug)
            {
                client.SendDebugMessage(loggingEvent.RenderedMessage);
            }
        }
コード例 #4
0
        public void RawLogToRollbar()
        {
            var client = new RollbarClient("3203880e148b43b4b1a14430fb41957a");

            client.RequestStarting += this.RollbarClient_RequestStarting;
            client.RequestCompleted += this.RollbarClient_RequestCompleted;

            var notice = client.NoticeBuilder.CreateMessageNotice("This is a test message");

            notice.Level = "error";
            notice.Title = "Test Message";

            client.Send(notice);

            while (wait) { }
        }