public Target GetTarget(Action <SentryNLogOptions> customConfig = null, bool asyncTarget = false)
            {
                var options = Options;

                if (customConfig != null)
                {
                    options = new SentryNLogOptions();
                    customConfig(options);
                }

                Target target = new SentryTarget(
                    options,
                    HubAccessor,
                    SdkDisposeHandle,
                    Clock)
                {
                    Name = "sentry",
                    Dsn  = ValidDsnWithoutSecret,
                };

                if (asyncTarget)
                {
                    target = new AsyncTargetWrapper(target)
                    {
                        Name = "sentry_async"
                    };
                }
                return(target);
            }
Esempio n. 2
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.</param>
        /// <param name="targetName">   The name to give the new target.</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,
                                                     string targetName,
                                                     Action <SentryNLogOptions> optionsConfig = null)
        {
            var options = new SentryNLogOptions();

            optionsConfig?.Invoke(options);

            Target.Register <SentryTarget>("Sentry");

            var target = new SentryTarget(options)
            {
                Name   = targetName,
                Layout = "${message}",
            };

            if (dsn != null && options.Dsn == null)
            {
                options.Dsn = new Dsn(dsn);
            }

            configuration?.AddTarget(targetName, target);

            configuration?.AddRuleForAllLevels(targetName);

            return(configuration);
        }
        /// <summary>
        /// Adds a target for Sentry to the NLog configuration.
        /// </summary>
        /// <param name="configuration">The NLog configuration.</param>
        /// <param name="dsn">          The sentry DSN.</param>
        /// <param name="targetName">   The name to give the new target.</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,
                                                     string targetName,
                                                     Action <SentryNLogOptions>?optionsConfig = null)
        {
            // Not to throw on code that ignores nullability warnings.
            // ReSharper disable once ConditionIsAlwaysTrueOrFalse
            if (configuration is null)
            {
                return(configuration !);
            }

            var options = new SentryNLogOptions();

            optionsConfig?.Invoke(options);

            Target.Register <SentryTarget>("Sentry");

            var target = new SentryTarget(options)
            {
                Name   = targetName,
                Layout = "${message}",
            };

            if (dsn != null && string.IsNullOrWhiteSpace(options.Dsn))
            {
                options.Dsn = dsn;
            }

            configuration.AddTarget(targetName, target);

            configuration.AddRuleForAllLevels(targetName);

            return(configuration);
        }
Esempio n. 4
0
 /// <summary>
 /// Creates a new instance of <see cref="SentryTarget"/>.
 /// </summary>
 public SentryTarget(SentryNLogOptions options)
     : this(
         options,
         () => HubAdapter.Instance,
         null,
         SystemClock.Clock)
 {
 }
Esempio n. 5
0
        public void AddTag_SetToTarget()
        {
            var sut = new SentryNLogOptions();

            Layout layout = "b";

            sut.AddTag("a", layout);

            var tag = Assert.Single(sut.Tags);

            Assert.Equal("a", tag.Name);
            Assert.Equal(layout, tag.Layout);
        }
Esempio n. 6
0
    internal SentryTarget(SentryNLogOptions options, Func <IHub> hubAccessor, IDisposable?sdkInstance, ISystemClock clock)
    {
        Options     = options;
        HubAccessor = hubAccessor;
        _clock      = clock;

        // Overrides default layout. Still will be explicitly overwritten if manually configured in the
        // NLog.config file.
        Layout                 = "${message}";
        BreadcrumbCategory     = Options.BreadcrumbCategoryLayout ?? "${logger}";
        IncludeEventProperties = true;

        if (sdkInstance != null)
        {
            _sdkDisposable = sdkInstance;
        }
    }
Esempio n. 7
0
            public SentryTarget GetTarget(Action <SentryNLogOptions> customConfig = null)
            {
                var options = Options;

                if (customConfig != null)
                {
                    options = new SentryNLogOptions();
                    customConfig(options);
                }

                var target = new SentryTarget(
                    options,
                    HubAccessor,
                    SdkDisposeHandle,
                    Clock)
                {
                    Dsn = ValidDsnWithoutSecret,
                };

                return(target);
            }
Esempio n. 8
0
 /// <summary>
 /// Add any desired additional tags that will be sent with every message.
 /// </summary>
 /// <param name="options">The options being configured.</param>
 /// <param name="name">   The name of the tag.</param>
 /// <param name="layout"> The layout to be rendered for the tag</param>
 public static void AddTag(this SentryNLogOptions options, string name, Layout layout)
 {
     options.Tags.Add(new TargetPropertyWithContext(name, layout));
 }
    public void Ctor_MinimumBreadcrumbLevel_Information()
    {
        var options = new SentryNLogOptions();

        Assert.Equal(LogLevel.Info, options.MinimumBreadcrumbLevel);
    }
    public void Ctor_MinimumEventLevel_Error()
    {
        var options = new SentryNLogOptions();

        Assert.Equal(LogLevel.Error, options.MinimumEventLevel);
    }