Exemple #1
0
        public static void Error(string message)
        {
            if (client == null)
            {
                setupClient();
            }

            var sentryEvent = new SentryEvent(message)
            {
                Level = ErrorLevel.Error
            };

            client?.CaptureAsync(sentryEvent);

            Log.Error(message);
        }
        public async Task Invoke(HttpContext context)
        {
            try
            {
                await _next(context);
            }
            catch (Exception ex)
            {
                if (!string.IsNullOrWhiteSpace(_options.Dsn))
                {
                    try
                    {
                        var sentry = new RavenClient(
                            _options.Dsn,
                            sentryRequestFactory: new AspNetCoreSentryRequestFactory(context));
                        await sentry.CaptureAsync(new SentryEvent(ex));
                    }
                    catch (Exception sentryEx)
                    {
                        throw new Exception($"Logging to sentry failed, {sentryEx}", ex);
                    }
                }

                throw;
            }
        }
Exemple #3
0
        void LogException(Exception ex)
        {
            if (Debugger.IsAttached)
            {
                Debugger.Break();
            }
            SetProgress(ex.Message);
            try
            {
                _core.Logger.Error(this, ex.Message);
            }
            catch { }
            if (ex == null)
            {
                return;
            }
            int tries = 0;

            while (tries < 3)
            {
                tries++;
                try
                {
                    var ravenClient = new RavenClient("https://[email protected]/1489869");
                    AsyncHelpers.RunSync(() => ravenClient.CaptureAsync(new SentryEvent(ex)), 7000);
                    tries = 10;
                    _logger?.Error("App", ex.Message);
                    _logger?.Error("App", ex.StackTrace);
                }
                catch
                {
                    AsyncHelpers.RunSync(async() => await Task.Delay(3000), 4000);
                }
            }
        }
        static async Task Main(string[] args)
#endif
        {
            var dsn = Environment.GetEnvironmentVariable("SENTRY_DSN")
                      ?? "https://[email protected]/1";

            System.Console.WriteLine("Using DSN: " + dsn);

            var framework = TargetFramework();

            System.Console.WriteLine("Built against: " + framework);
            var       client = new RavenClient(dsn);
            Exception ex     = null;

#if NET40 || NET35
            ex = new Exception(args.FirstOrDefault() ?? "I love throwing.");
#else
            try
            {
                var neverSet = await Thrower(new List <Program>());
            }
            catch (Exception e)
            {
                ex = e;
            }
#endif
            ex.Data.Add("AppBuiltTargetingFramework", framework);

#if NET40 || NET35
            var id = client.Capture(new SentryEvent(ex));
#else
            var id = await client.CaptureAsync(new SentryEvent(ex));
#endif
            Console.WriteLine("Event id: " + id);
        }
Exemple #5
0
        public async Task SendMessageAsync(string message, Exception ex, string errorLevel)
        {
            if (string.IsNullOrEmpty(message) || ex == null || string.IsNullOrEmpty(errorLevel))
            {
                return;
            }
            var sentryMessage = new SentryMessage(string.Format(
                                                      "Message: {0} \r\n\r\nException:{1}",
                                                      message,
                                                      ex.ToString()));
            var sentryEvent = new SentryEvent(sentryMessage)
            {
                Level = ErrorLevel.Error,
                Tags  = new Dictionary <string, string>()
                {
                    { "device.model", DeviceInfoHelper.DeviceModel.GetStringForNullOrEmptyProperty("0") },
                    { "device.arch", DeviceInfoHelper.SystemArchitecture.GetStringForNullOrEmptyProperty("unknown") },
                    { "app.version", DeviceInfoHelper.ApplicationVersion.GetStringForNullOrEmptyProperty("2.7.9.0") },
                    { "system.version", DeviceInfoHelper.SystemVersion.GetStringForNullOrEmptyProperty("0") },
                    { "system.family", DeviceInfoHelper.SystemFamily.GetStringForNullOrEmptyProperty("unknown") },
                }
            };

            var result = await ravenClient.CaptureAsync(sentryEvent).ConfigureAwait(false);
        }
Exemple #6
0
        private static void Report(SentryEvent @event)
        {
            @event.Tags.Add("ARCH", Environment.Is64BitOperatingSystem ? "x64" : "x86");
            @event.Tags.Add("OS", Environment.OSVersion.VersionString);
            @event.Tags.Add("NET", Environment.Version.ToString());

            ravenClient.CaptureAsync(@event);
        }
Exemple #7
0
        public Task LogError(Exception exception)
        {
            Log4NetLogger.Error($"Exception was handled. (ExceptionMessage: {exception.Message}, ExceptionName: {exception.GetType().Name})");

            return(RavenClient.CaptureAsync(new SentryEvent(exception)
            {
                Level = ErrorLevel.Error
            }));
        }
Exemple #8
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
                    });
                }
            };
        }
Exemple #9
0
        public static void Error(Exception ex)
        {
            var ev = new SharpRaven.Data.SentryEvent(ex)
            {
                Level = SharpRaven.Data.ErrorLevel.Error
            };

            ev.Tags.Add("ARCH", Environment.Is64BitOperatingSystem ? "x64" : "x86");
            ev.Tags.Add("OS", Environment.OSVersion.VersionString);
            ev.Tags.Add("NET", Environment.Version.ToString());

            ravenClient.CaptureAsync(ev);
        }
Exemple #10
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
                    });
                }
            };
        }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }

            #region Swagger middleware
            // Enable middleware to serve generated Swagger as a JSON endpoint.
            app.UseSwagger();

            // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), specifying the Swagger JSON endpoint.
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
            });
            #endregion

            #region Global exeption handler
            app.UseExceptionHandler(config =>
            {
                config.Run(async context =>
                {
                    context.Response.StatusCode  = 500;
                    context.Response.ContentType = "application/json";

                    var error = context.Features.Get <IExceptionHandlerFeature>();
                    if (error != null)
                    {
                        var ex = error.Error;


                        RavenClient ravenClient = new RavenClient(Configuration["SentryDsn"]);
                        await ravenClient.CaptureAsync(new SharpRaven.Data.SentryEvent(ex));
                    }
                });
            });
            #endregion

            app.UseHttpsRedirection();
            app.UseMvc();
        }
Exemple #12
0
 // Attempt to write to sentry but if it does not work then continue on.
 private static async void LogToSentry(Exception exception, Dictionary <string, string> additionalData)
 {
     try
     {
         SetSentryData(exception, "Excel-Version", Utilities.ExcelVersionNumber);
         SetSentryData(exception, "Addin-Release-Version", Utilities.ReleaseVersion);
         SetSentryData(exception, "X-API-Token", QuandlConfig.ApiKey);
         if (additionalData != null)
         {
             additionalData.ForEach(k => SetSentryData(exception, k.Key, k.Value));
         }
         var ravenClient = new RavenClient(Settings.Default.SentryUrl);
         await ravenClient.CaptureAsync(new SentryEvent(exception));
     }
     catch (Exception e)
     {
         Trace.WriteLine(e.Message);
         Trace.WriteLine(e.StackTrace);
     }
 }
        public static async Task SendMessageAsync(RavenClient ravenClient, string message, Exception ex, ErrorLevel errorLevel)
        {
            var sentryMessage = new SentryMessage(string.Format(
                                                      "Message: {0} \r\n\r\nException:{1}",
                                                      message,
                                                      ex.ToString()));
            var sentryEvent = new SentryEvent(sentryMessage)
            {
                Level = ErrorLevel.Error,
                Tags  = new Dictionary <string, string>()
                {
                    { "device.model", DeviceInfoHelper.DeviceModel },
                    { "device.arch", DeviceInfoHelper.SystemArchitecture },
                    { "app.version", DeviceInfoHelper.ApplicationVersion },
                    { "system.version", DeviceInfoHelper.SystemVersion },
                    { "system.family", DeviceInfoHelper.SystemFamily },
                }
            };

            var result = await ravenClient.CaptureAsync(sentryEvent).ConfigureAwait(false);
        }
Exemple #14
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
                    });
                }
            };
        }
        public Task <string> ReportErrorAsync(Exception ex)
        {
            var sentryEvent = new SentryEvent(ex);

            return(_sentryClient.CaptureAsync(sentryEvent));
        }
Exemple #16
0
 public void CaptureAsync(Exception e)
 {
     _client.CaptureAsync(new SentryEvent(e));
 }
Exemple #17
0
 public async Task LogAsync(Exception ex)
 {
     await ravenClient.CaptureAsync(new SentryEvent(ex));
 }