public void GeneralInformationBreadcrumb()
 {
     _sentryClient.AddTrail(new Breadcrumb("General Information")
     {
         Message = "General information for the exception",
         Data    = new Dictionary <string, string>()
         {
             { nameof(DateTime), DateTime.Now.ToLongDateString() }
         }
     });
 }
 public void MessageBreadcrumb <T>(T message)
 {
     _sentryClient.AddTrail(new Breadcrumb("Message")
     {
         Message = "Server received following message",
         Level   = BreadcrumbLevel.Info,
         Data    = new Dictionary <string, string>()
         {
             { "message", message.ToString() }
         }
     });
 }
Example #3
0
 public static void LogSentryBreadcrumb(string category, string message, BreadcrumbLevel level = BreadcrumbLevel.Info)
 {
     Console.Out.WriteLine(String.Format("{0} : {1}", category, message));
     if (ravenClient != null)
     {
         ravenClient.AddTrail(new Breadcrumb(category)
         {
             Message = message, Type = BreadcrumbType.Navigation
         });
     }
 }
Example #4
0
        public RavenLogger(OsuGame game)
        {
            raven.Release = game.Version;

            if (!game.IsDeployedBuild)
            {
                return;
            }

            Exception lastException = null;

            Logger.NewEntry += entry =>
            {
                if (entry.Level < LogLevel.Verbose)
                {
                    return;
                }

                var exception = entry.Exception;

                if (exception != null)
                {
                    if (exception is IOException ioe)
                    {
                        // disk full exceptions, see https://stackoverflow.com/a/9294382
                        const int hr_error_handle_disk_full = unchecked ((int)0x80070027);
                        const int hr_error_disk_full        = unchecked ((int)0x80070070);

                        if (ioe.HResult == hr_error_handle_disk_full || ioe.HResult == hr_error_disk_full)
                        {
                            return;
                        }
                    }

                    // since we let unhandled exceptions go ignored at times, we want to ensure they don't get submitted on subsequent reports.
                    if (lastException != null &&
                        lastException.Message == exception.Message && exception.StackTrace.StartsWith(lastException.StackTrace))
                    {
                        return;
                    }

                    lastException = exception;
                    queuePendingTask(raven.CaptureAsync(new SentryEvent(exception)));
                }
                else
                {
                    raven.AddTrail(new Breadcrumb(entry.Target.ToString(), BreadcrumbType.Navigation)
                    {
                        Message = entry.Message
                    });
                }
            };
        }
Example #5
0
        public RavenLogger(OsuGame game)
        {
            raven.Release = game.Version;

            if (!game.IsDeployedBuild)
            {
                return;
            }

            Exception lastException = null;

            Logger.NewEntry += entry =>
            {
                if (entry.Level < LogLevel.Verbose)
                {
                    return;
                }

                var exception = entry.Exception;

                if (exception != null)
                {
                    if (!shouldSubmitException(exception))
                    {
                        return;
                    }

                    // since we let unhandled exceptions go ignored at times, we want to ensure they don't get submitted on subsequent reports.
                    if (lastException != null &&
                        lastException.Message == exception.Message && exception.StackTrace.StartsWith(lastException.StackTrace))
                    {
                        return;
                    }

                    lastException = exception;
                    queuePendingTask(raven.CaptureAsync(new SentryEvent(exception)
                    {
                        Message = entry.Message
                    }));
                }
                else
                {
                    raven.AddTrail(new Breadcrumb(entry.Target.ToString(), BreadcrumbType.Navigation)
                    {
                        Message = entry.Message
                    });
                }
            };
        }
Example #6
0
        public RavenLogger(GDEApp app)
        {
            Logger.NewEntry += entry =>
            {
                if (entry.Level < LogLevel.Verbose)
                {
                    return;
                }

                var exception = entry.Exception;

                if (exception != null)
                {
                    if (exception is IOException ioe)
                    {
                        if (ioe.HResult == HandleDiskFullError || ioe.HResult == DiskFullError)
                        {
                            return;
                        }
                    }

                    // since we let unhandled exceptions go ignored at times, we want to ensure they don't get submitted on subsequent reports.
                    if (lastException != null && lastException.Message == exception.Message && exception.StackTrace.StartsWith(lastException.StackTrace))
                    {
                        return;
                    }

                    lastException = exception;
                    QueuePendingTask(raven.CaptureAsync(new SentryEvent(exception)));
                }
                else
                {
                    raven.AddTrail(new Breadcrumb(entry.Target.ToString(), BreadcrumbType.Navigation)
                    {
                        Message = entry.Message
                    });
                }
            };
        }
Example #7
0
        public void AddSentryBreadCrum(String title, Dictionary <string, object> data = null, String message = null)
        {
            var breadcrumb = new Breadcrumb(title)
            {
                Level = BreadcrumbLevel.Info,
            };

            if (data != null)
            {
                var dataDic = new Dictionary <string, string>();
                foreach (KeyValuePair <string, object> pair in data)
                {
                    string key = pair.Key;
                    string value;

                    try
                    {
                        value = JsonConvert.SerializeObject(pair.Value);
                    }
                    catch (Exception)
                    {
                        value = "Can't convert to json";
                    }

                    dataDic.Add(key, value);
                }

                breadcrumb.Data = dataDic;
            }

            if (message != null)
            {
                breadcrumb.Message = message;
            }

            _ravenClient.AddTrail(breadcrumb);
        }
Example #8
0
        protected override void Write(LogEventInfo logEvent)
        {
            try
            {
                lock (Tags)
                {
                    foreach (var tag in Tags)
                    {
                        _client.Tags[tag.Key] = tag.Value;
                    }
                }

                var message = logEvent.FormattedMessage;

                if (!string.IsNullOrEmpty(message))
                {
                    _client.AddTrail(new Breadcrumb(logEvent.LoggerName, BreadcrumbType.Navigation)
                    {
                        Level   = GetLevel(logEvent.Level),
                        Message = message
                    });
                }

                if (logEvent.Level.Ordinal < LogLevel.Error.Ordinal)
                {
                    return;
                }

                var extras = logEvent.Properties.ToDictionary(x => x.Key.ToString(), x => x.Value.ToString());
                extras["args"] = string.Join(" ", Environment.GetCommandLineArgs().Skip(1));

                var ex = logEvent.Exception;

                if (ex is AggregateException aggException)
                {
                    ex = aggException.Flatten();
                }

                var sentryEvent = new SentryEvent(ex)
                {
                    Level   = LoggingLevelMap[logEvent.Level],
                    Message = string.IsNullOrWhiteSpace(message) ? null : new SentryMessage(message),
                    Extra   = extras
                };

                if (ex != null)
                {
                    foreach (DictionaryEntry data in ex.Data)
                    {
                        extras.Add(data.Key.ToString(), data.Value?.ToString());
                    }
                }

                lock (_client)
                {
                    _client.Logger = logEvent.LoggerName;
                    var result = _client.Capture(sentryEvent);

                    _client.Logger = "root";

                    if (ex != null)
                    {
                        ex.Data[SENTRY_REPORTED] = true;
                        ex.Data["SENTRY_ID"]     = result;
                    }
                }
            }
            catch (Exception e)
            {
                OnError(e);
            }
        }
Example #9
0
        protected override void Write(LogEventInfo logEvent)
        {
            if (_unauthorized)
            {
                return;
            }

            try
            {
                _client.AddTrail(new Breadcrumb(logEvent.LoggerName)
                {
                    Level = BreadcrumbLevelMap[logEvent.Level], Message = logEvent.FormattedMessage
                });

                // don't report non-critical events without exceptions
                if (!IsSentryMessage(logEvent))
                {
                    return;
                }

                var fingerPrint = GetFingerPrint(logEvent);
                if (!_debounce.Allowed(fingerPrint))
                {
                    return;
                }

                var extras = logEvent.Properties.ToDictionary(x => x.Key.ToString(), x => x.Value.ToString());
                extras.Remove("Sentry");
                _client.Logger = logEvent.LoggerName;

                if (logEvent.Exception != null)
                {
                    foreach (DictionaryEntry data in logEvent.Exception.Data)
                    {
                        extras.Add(data.Key.ToString(), data.Value.ToString());
                    }
                }

                var sentryMessage = new SentryMessage(logEvent.Message, logEvent.Parameters);

                var sentryEvent = new SentryEvent(logEvent.Exception)
                {
                    Level       = LoggingLevelMap[logEvent.Level],
                    Message     = sentryMessage,
                    Extra       = extras,
                    Fingerprint =
                    {
                        logEvent.Level.ToString(),
                        logEvent.LoggerName,
                        logEvent.Message
                    }
                };

                if (logEvent.Exception != null)
                {
                    sentryEvent.Fingerprint.Add(logEvent.Exception.GetType().FullName);
                }

                if (logEvent.Properties.ContainsKey("Sentry"))
                {
                    sentryEvent.Fingerprint.Clear();
                    Array.ForEach((string[])logEvent.Properties["Sentry"], sentryEvent.Fingerprint.Add);
                }

                var runTimeVersion = Environment.GetEnvironmentVariable("RUNTIME_VERSION");

                sentryEvent.Tags.Add("runtime_version", $"{PlatformInfo.PlatformName} {runTimeVersion}");

                _client.Capture(sentryEvent);
            }
            catch (Exception e)
            {
                OnError(e);
            }
        }