exceptionless / Exceptionless.Net

Exceptionless clients for the .NET platform
https://exceptionless.com
Other
555 stars 142 forks source link

NLog - Ability to add fields from Code #209

Closed gkathire closed 1 year ago

gkathire commented 5 years ago

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);
        }
niemyjski commented 5 years ago

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 commented 1 year ago

I've fixed this in the latest nightly build.