Captures a string message, optionally formatted with arguments, as sent to Sentry.
Ejemplo n.º 1
0
        public void Message_ReturnsMessage()
        {
            const string format = "Format something {0:N} in here";
            var arg = Guid.NewGuid();
            SentryMessage message = new SentryMessage(format, arg);

            Assert.That(message.Message, Is.EqualTo(format));
        }
Ejemplo n.º 2
0
        public void CaptureException_WithMessageFormat_ReturnsValidID()
        {
            object[] args = Enumerable.Range(0, 5).Select(i => Guid.NewGuid()).Cast<object>().ToArray();
            var message = new SentryMessage("A {0:N} B {1:N} C {2:N} D {3:N} F {4:N}.", args);
            var id = this.ravenClient.CaptureException(new Exception("Test without a stacktrace."), message);
            //Console.WriteLine("Sent packet: " + id);

            Assert.That(id, Is.Not.Null.Or.Empty);
            Assert.That(Guid.Parse(id), Is.Not.Null);
        }
Ejemplo n.º 3
0
        public JsonPacket Create(string project,
            SentryMessage message,
            ErrorLevel level = ErrorLevel.Info,
            IDictionary<string, string> tags = null,
            string[] fingerprint = null,
            object extra = null)
        {
            var @event = new SentryEvent(message)
            {
                Level = level,
                Extra = extra,
                Tags = tags,
                Fingerprint = fingerprint
            };

            return Create(project, @event);
        }
Ejemplo n.º 4
0
        public JsonPacket Create(string project,
                                 SentryMessage message,
                                 ErrorLevel level = ErrorLevel.Info,
                                 IDictionary <string, string> tags = null,
                                 string[] fingerprint = null,
                                 object extra         = null)
        {
            var @event = new SentryEvent(message)
            {
                Level       = level,
                Extra       = extra,
                Tags        = tags,
                Fingerprint = fingerprint
            };

            return(Create(project, @event));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates a new instance of
        /// <see cref="JsonPacket" /> for the specified
        /// <paramref name="project" />.
        /// </summary>
        /// <param name="project">The project.</param>
        /// <param name="message">The message to capture.</param>
        /// <param name="level">The <see cref="ErrorLevel" /> of the captured <paramref name="message" />. Default <see cref="ErrorLevel.Info" />.</param>
        /// <param name="tags">The tags to annotate the captured <paramref name="message" /> with.</param>
        /// <param name="extra">The extra metadata to send with the captured <paramref name="message" />.</param>
        /// <returns>
        /// A new instance of <see cref="JsonPacket" /> for the specified <paramref name="project" />.
        /// </returns>
        public JsonPacket Create(string project,
                                 SentryMessage message,
                                 ErrorLevel level = ErrorLevel.Info,
                                 IDictionary <string, string> tags = null,
                                 object extra = null)
        {
            var json = new JsonPacket(project)
            {
                Message = message != null?message.ToString() : null,
                              MessageObject = message,
                              Level         = level,
                              Tags          = tags,
                              Extra         = extra
            };

            return(OnCreate(json));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates a new instance of
        /// <see cref="JsonPacket" /> for the specified
        /// <paramref name="project" />.
        /// </summary>
        /// <param name="project">The project.</param>
        /// <param name="message">The message to capture.</param>
        /// <param name="level">The <see cref="ErrorLevel" /> of the captured <paramref name="message" />. Default <see cref="ErrorLevel.Info" />.</param>
        /// <param name="tags">The tags to annotate the captured <paramref name="message" /> with.</param>
        /// <param name="extra">The extra metadata to send with the captured <paramref name="message" />.</param>
        /// <returns>
        /// A new instance of <see cref="JsonPacket" /> for the specified <paramref name="project" />.
        /// </returns>
        public JsonPacket Create(string project,
                                 SentryMessage message,
                                 ErrorLevel level = ErrorLevel.Info,
                                 IDictionary<string, string> tags = null,
                                 object extra = null)
        {
            var json = new JsonPacket(project)
            {
                Message = message != null ? message.ToString() : null,
                MessageObject = message,
                Level = level,
                Tags = tags,
                Extra = extra
            };

            return OnCreate(json);
        }
Ejemplo n.º 7
0
        public async Task<string> CaptureExceptionAsync(Exception exception,
                                                        SentryMessage message = null,
                                                        ErrorLevel level = ErrorLevel.Error,
                                                        IDictionary<string, string> tags = null,
                                                        string[] fingerprint = null,
                                                        object extra = null)
        {
            var @event = new SentryEvent(exception)
            {
                Message = message,
                Level = level,
                Extra = extra,
                Tags = tags,
                Fingerprint = fingerprint
            };

            return await CaptureAsync(@event);
        }
Ejemplo n.º 8
0
        public JsonPacket Create(string project,
                                 Exception exception,
                                 SentryMessage message             = null,
                                 ErrorLevel level                  = ErrorLevel.Error,
                                 IDictionary <string, string> tags = null,
                                 string[] fingerprint              = null,
                                 object extra = null)
        {
            var @event = new SentryEvent(exception)
            {
                Message     = message,
                Level       = level,
                Extra       = extra,
                Tags        = tags,
                Fingerprint = fingerprint,
            };

            return(Create(project, @event));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Creates a new instance of
        /// <see cref="JsonPacket" /> for the specified
        /// <paramref name="project" />, with the
        /// given
        /// <paramref name="exception" />.
        /// </summary>
        /// <param name="project">The project.</param>
        /// <param name="exception">The <see cref="Exception" /> to capture.</param>
        /// <param name="message">The optional message to capture. Default: <see cref="Exception.Message" />.</param>
        /// <param name="level">The <see cref="ErrorLevel" /> of the captured <paramref name="exception" />. Default: <see cref="ErrorLevel.Error" />.</param>
        /// <param name="tags">The tags to annotate the captured <paramref name="exception" /> with.</param>
        /// <param name="fingerprint">The custom fingerprint to annotate the captured <paramref name="message" /> with.</param>
        /// <param name="extra">The extra metadata to send with the captured <paramref name="exception" />.</param>
        /// <returns>
        /// A new instance of
        /// <see cref="JsonPacket" /> for the specified
        /// <paramref name="project" />, with the
        /// given
        /// <paramref name="exception" />.
        /// </returns>
        public JsonPacket Create(string project,
                                 Exception exception,
                                 SentryMessage message             = null,
                                 ErrorLevel level                  = ErrorLevel.Error,
                                 IDictionary <string, string> tags = null,
                                 string[] fingerprint              = null,
                                 object extra = null)
        {
            var json = new JsonPacket(project, exception)
            {
                Message = message != null?message.ToString() : exception.Message,
                              MessageObject = message,
                              Level         = level,
                              Tags          = tags,
                              Fingerprint   = fingerprint,
                              Extra         = Merge(extra, exception)
            };

            return(OnCreate(json));
        }
Ejemplo n.º 10
0
        public string CaptureMessage(SentryMessage message,
            ErrorLevel level = ErrorLevel.Info,
            IDictionary<string, string> tags = null,
            string[] fingerprint = null,
            object extra = null)
        {
            var @event = new SentryEvent(message)
            {
                Level = level,
                Extra = extra,
                Tags = MergeTags(tags),
                Fingerprint = fingerprint
            };

            return Capture(@event);
        }
Ejemplo n.º 11
0
        public void ToString_ReturnsMessage()
        {
            string stringMessage = Guid.NewGuid().ToString("N");
            SentryMessage message = new SentryMessage(stringMessage);

            Assert.That(message.ToString(), Is.EqualTo(stringMessage));
        }
Ejemplo n.º 12
0
        public async Task<string> CaptureMessageAsync(SentryMessage message,
                                                      ErrorLevel level = ErrorLevel.Info,
                                                      IDictionary<string, string> tags = null,
                                                      string[] fingerprint = null,
                                                      object extra = null)
        {
            var @event = new SentryEvent(message)
            {
                Level = level,
                Extra = extra,
                Tags = tags,
                Fingerprint = fingerprint
            };

            return await CaptureAsync(@event);
        }
Ejemplo n.º 13
0
        public string CaptureException(Exception exception,
            SentryMessage message = null,
            ErrorLevel level = ErrorLevel.Error,
            IDictionary<string, string> tags = null,
            string[] fingerprint = null,
            object extra = null)
        {
            var @event = new SentryEvent(exception)
            {
                Message = message,
                Level = level,
                Extra = extra,
                Tags = MergeTags(tags),
                Fingerprint = fingerprint
            };

            return Capture(@event);
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Captures the <see cref="Exception" />.
 /// </summary>
 /// <param name="exception">The <see cref="Exception" /> to capture.</param>
 /// <param name="message">The optional messge to capture. Default: <see cref="Exception.Message" />.</param>
 /// <param name="level">The <see cref="ErrorLevel" /> of the captured <paramref name="exception" />. Default: <see cref="ErrorLevel.Error" />.</param>
 /// <param name="tags">The tags to annotate the captured <paramref name="exception" /> with.</param>
 /// <param name="extra">The extra metadata to send with the captured <paramref name="exception" />.</param>
 /// <returns>
 /// The <see cref="JsonPacket.EventID" /> of the successfully captured <paramref name="exception" />, or <c>null</c> if it fails.
 /// </returns>
 public string CaptureException(Exception exception,
     SentryMessage message = null,
     ErrorLevel level = ErrorLevel.Error,
     IDictionary<string, string> tags = null,
     object extra = null)
 {
     JsonPacket packet = this.jsonPacketFactory.Create(this.currentDsn.ProjectID,
                                                       exception,
                                                       message,
                                                       level,
                                                       tags,
                                                       extra);
     return Send(packet, CurrentDsn);
 }
Ejemplo n.º 15
0
 /// <summary>Initializes a new instance of the <see cref="SentryEvent"/> class.</summary>
 /// <param name="message">The message to capture.</param>
 public SentryEvent(SentryMessage message)
     : this()
 {
     Message = message;
 }
Ejemplo n.º 16
0
        public void Parameters_ReturnsParameters()
        {
            const string format = "Format something {0:N} in here";
            var arg = Guid.NewGuid();
            SentryMessage message = new SentryMessage(format, arg);

            Assert.That(message.Parameters, Has.Length.EqualTo(1));
            Assert.That(message.Parameters[0], Is.EqualTo(arg));
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Captures the message.
 /// </summary>
 /// <param name="message">The message to capture.</param>
 /// <param name="level">The <see cref="ErrorLevel" /> of the captured <paramref name="message" />. Default <see cref="ErrorLevel.Info" />.</param>
 /// <param name="tags">The tags to annotate the captured <paramref name="message" /> with.</param>
 /// <param name="extra">The extra metadata to send with the captured <paramref name="message" />.</param>
 /// <returns>
 /// The <see cref="JsonPacket.EventID" /> of the successfully captured <paramref name="message" />, or <c>null</c> if it fails.
 /// </returns>
 public string CaptureMessage(SentryMessage message,
     ErrorLevel level = ErrorLevel.Info,
     Dictionary<string, string> tags = null,
     object extra = null)
 {
     JsonPacket packet = this.jsonPacketFactory.Create(CurrentDsn.ProjectID, message, level, tags, extra);
     return Send(packet, CurrentDsn);
 }
Ejemplo n.º 18
0
        public JsonPacket Create(string project,
            Exception exception,
            SentryMessage message = null,
            ErrorLevel level = ErrorLevel.Error,
            IDictionary<string, string> tags = null,
            string[] fingerprint = null,
            object extra = null)
        {
            var @event = new SentryEvent(exception)
            {
                Message = message,
                Level = level,
                Extra = extra,
                Tags = tags,
                Fingerprint = fingerprint,
            };

            return Create(project, @event);
        }
Ejemplo n.º 19
0
 /// <summary>Initializes a new instance of the <see cref="SentryEvent"/> class.</summary>
 /// <param name="message">The message to capture.</param>
 public SentryEvent(SentryMessage message)
     : this()
 {
     Message = message;
 }
Ejemplo n.º 20
0
        public void ToString_ReturnsFormattedString()
        {
            Guid arg = Guid.NewGuid();
            SentryMessage message = new SentryMessage("Format something {0:N} in here", arg);

            Assert.That(message.ToString(), Is.StringContaining(arg.ToString("N")));
        }
Ejemplo n.º 21
0
        public void CaptureMessage_WithFormat_ReturnsValidID()
        {
            object[] args = Enumerable.Range(0, 5).Select(i => Guid.NewGuid()).Cast<object>().ToArray();
            var message = new SentryMessage("Lorem %s ipsum %s dolor %s sit %s amet %s.", args);
            var id = this.ravenClient.CaptureMessage(message);
            //Console.WriteLine("Sent packet: " + id);

            Assert.That(id, Is.Not.Null);
            Assert.That(Guid.Parse(id), Is.Not.Null);
        }
Ejemplo n.º 22
0
        public void Message_IsImplicitlyConvertedTo_String()
        {
            string message = new SentryMessage("Hello");

            Assert.That(message, Is.EqualTo("Hello"));
        }