Exceptionless.Net icon indicating copy to clipboard operation
Exceptionless.Net copied to clipboard

NLog - Ability to add fields from Code

Open gkathire opened this issue 6 years ago • 1 comments

I dont use nlog.config file for configuring the logger. All the configuration is done on the fly from the code. I'm trying to add additional field to the ExceptionlessTarget object but I cannot, because the Fields property is readonly. Can you make this property non readonly so that we can add values to it dynamically ?

Here is how I configure using the code :

        if (logConfig.EnableExceptionlessTarget)
        {
            var target = new Exceptionless.NLog.ExceptionlessTarget
            {
                Name = "ExceptionlessTarget",
                ApiKey = logConfig.ExceptionlessApiKey,
                ServerUrl = logConfig.ExceptionlessServerUrl
            };

            var aWrapper = new AsyncTargetWrapper { Name = "ExceptionLessTargetWrapper_1", OverflowAction = AsyncTargetWrapperOverflowAction.Grow, WrappedTarget = target };
            config.AddTarget(AppLoggerName + "-exceptionLess", aWrapper);
            var rule = new LoggingRule(AppLoggerName, LogLevel.Trace, aWrapper);
            config.LoggingRules.Add(rule);
        }

gkathire avatar Apr 25 '19 01:04 gkathire

That sounds reasonable, can you please submit a pr for this and some sample code to our sample so we can see this in action and ensure we don't break it going forward :).

niemyjski avatar Apr 25 '19 03:04 niemyjski

I've fixed this in the latest nightly build.

niemyjski avatar Apr 12 '23 13:04 niemyjski