Exemplo n.º 1
0
        public static void Init(LoggingConfiguration config)
        {
            // https://github.com/mkaring/ConfuserEx
            // https://docs.sentry.io/platforms/dotnet/nlog/

            config.AddSentry(o =>
            {
                o.Dsn = __dsn;
                //Optionally specify a separate format for message
                o.Layout = "${message}";
                // Optionally specify a separate format for breadcrumbs
                o.BreadcrumbLayout = "${logger}: ${message}";

                o.IgnoreEventsWithNoException = true;
                o.InitializeSdk = true;

                // Debug and higher are stored as breadcrumbs (default is Info)
                o.MinimumBreadcrumbLevel = LogLevel.Debug;
                // Error and higher is sent as event (default is Error)
                o.MinimumEventLevel = LogLevel.Error;
                // Send the logger name as a tag
                o.AddTag("logger", "${logger}");

                o.Environment                   = "PRODUCTION";
                o.AttachStacktrace              = true;
                o.SendDefaultPii                = true;
                o.ShutdownTimeoutSeconds        = 5;
                o.IncludeEventDataOnBreadcrumbs = true;
            });
            LogManager.ReconfigExistingLoggers();
        }
        /// <summary>
        /// Adds a target for Sentry to the NLog configuration.
        /// </summary>
        /// <remarks>
        /// If DSN is not set, the SDK will look for an environment variable called SENTRY_DSN. If nothing is
        /// found, SDK is disabled.
        /// </remarks>
        /// <param name="configuration">The NLog configuration.</param>
        /// <param name="optionsConfig">An optional action for configuring the Sentry target options.</param>
        /// <returns>The configuration.</returns>
        public static LoggingConfiguration AddSentry(this LoggingConfiguration configuration,
                                                     Action <SentryNLogOptions>?optionsConfig = null)
        {
            // Not to throw on code that ignores nullability warnings.
            // ReSharper disable once ConditionIsAlwaysTrueOrFalse
            if (configuration is null)
            {
                return(configuration !);
            }

            return(configuration.AddSentry(null, DefaultTargetName, optionsConfig));
        }
Exemplo n.º 3
0
        private static void AddSentryTarget(LoggingConfiguration logConfig)
        {
            const string SENTRY_DSN        = "https://e11516741a32440ca7a72b68d5af93df@sentry.do-ny3.svr.gw2blishhud.com/2";
            const string BREADCRUMB_LAYOUT = "${logger}: ${message}";

            logConfig.AddSentry(sentry => {
                sentry.Dsn              = new Dsn(SENTRY_DSN);
                sentry.Release          = $"blish_hud@{Program.OverlayVersion.Major}.{Program.OverlayVersion.Minor}.{Program.OverlayVersion.Patch}";
                sentry.Environment      = string.IsNullOrEmpty(Program.OverlayVersion.PreRelease) ? "Release" : Program.OverlayVersion.PreRelease;
                sentry.Debug            = true;
                sentry.BreadcrumbLayout = BREADCRUMB_LAYOUT;
                sentry.MaxBreadcrumbs   = 20;

                // We do this ourselves for our other logging
                // It's not working right now, though, for some reason
                //sentry.DisableAppDomainUnhandledExceptionCapture();

                sentry.BeforeBreadcrumb = delegate(Breadcrumb breadcrumb) {
                    string filteredMessage = StringUtil.ReplaceUsingStringComparison(breadcrumb.Message, Environment.UserName, "<filtered-username>", StringComparison.OrdinalIgnoreCase);

                    return(new Breadcrumb(filteredMessage, breadcrumb.Type, breadcrumb.Data, breadcrumb.Category, breadcrumb.Level));
                };

                sentry.BeforeSend = delegate(SentryEvent sentryEvent) {
                    sentryEvent.SetTag("locale", CultureInfo.CurrentUICulture.DisplayName);

                    if (!string.IsNullOrEmpty(Program.OverlayVersion.Build))
                    {
                        sentryEvent.SetTag("Build", Program.OverlayVersion.Build);
                    }

                    try {
                        // Display installed modules
                        if (GameService.Module != null && GameService.Module.Loaded)
                        {
                            var moduleDetails = GameService.Module.Modules.Select(m => new {
                                m.Manifest.Name,
                                m.Manifest.Namespace,
                                Version = m.Manifest.Version.ToString(),
                                m.Enabled
                            });

                            sentryEvent.SetExtra("Modules", moduleDetails.ToArray());
                        }
                    } catch (Exception unknownException) {
                        sentryEvent.SetExtra("Modules", $"Exception: {unknownException.Message}");
                    }

                    return(sentryEvent);
                };
            });
        }
Exemplo n.º 4
0
        private static void UsingCodeConfiguration()
        {
            // Other overloads exist, for example, configure the SDK with only the DSN or no parameters at all.
            var config = new LoggingConfiguration();

            config.AddSentry(options =>
            {
                options.Layout           = "${message}";
                options.BreadcrumbLayout = "${logger}: ${message}";   // Optionally specify a separate format for breadcrumbs

                options.MinimumBreadcrumbLevel = NLog.LogLevel.Debug; // Debug and higher are stored as breadcrumbs (default is Info)
                options.MinimumEventLevel      = NLog.LogLevel.Error; // Error and higher is sent as event (default is Error)

                // If DSN is not set, the SDK will look for an environment variable called SENTRY_DSN. If
                // nothing is found, SDK is disabled.
                options.Dsn = new Dsn("https://*****:*****@sentry.io/1340240");

                options.AttachStacktrace = true;
                options.SendDefaultPii   = true;              // Send Personal Identifiable information like the username of the user logged in to the device

                options.IncludeEventDataOnBreadcrumbs = true; // Optionally include event properties with breadcrumbs
                options.ShutdownTimeoutSeconds        = 5;

                options.AddTag("logger", "${logger}");  // Send the logger name as a tag

                options.HttpProxy = new WebProxy("http://127.0.0.1:8118", true)
                {
                    UseDefaultCredentials = true
                };
                // Other configuration
            });

            config.AddTarget(new DebuggerTarget("Debugger"));
            config.AddTarget(new ColoredConsoleTarget("Console"));

            config.AddRuleForAllLevels("Console");
            config.AddRuleForAllLevels("Debugger");

            LogManager.Configuration = config;
        }
Exemplo n.º 5
0
 /// <summary>
 /// Adds a target for Sentry to the NLog configuration.
 /// </summary>
 /// <param name="configuration">The NLog configuration.</param>
 /// <param name="dsn">
 /// The sentry DSN. If DSN is not set, the SDK will look for an environment variable called SENTRY_DSN.
 /// If nothing is found, SDK is disabled.
 /// </param>
 /// <param name="optionsConfig">An optional action for configuring the Sentry target options.</param>
 /// <returns>The configuration.</returns>
 public static LoggingConfiguration AddSentry(this LoggingConfiguration configuration,
                                              string dsn,
                                              Action <SentryNLogOptions> optionsConfig = null)
 {
     return(configuration.AddSentry(dsn, DefaultTargetName, optionsConfig));
 }
Exemplo n.º 6
0
        public void AddSentry_Parameterless_DefaultTargetName()
        {
            var actual = _sut.AddSentry();

            Assert.Equal(ConfigurationExtensions.DefaultTargetName, actual.AllTargets[0].Name);
        }