getsentry / getsentry/sentry-dotnet

Trimming support for NLog (Bump to NLog 5.2.2)

Open
#3,698 1 comment 0 reactions 0 assignees View on GitHub
.NET Task
Dominant language
C#
Stars
770
Forks
248
Avg merge
3d 4h
Merged PRs (30d)
49

Description

NLog 5.2.2 added trimming support. With growing adoption of MAUI, more and more users are trying to trim their apps.

We need to:

* Bump to 5.2.2
* Provide enough information about the custom configuration type used with NLog that it either doesn't try to load certain properties or the linker preserves any types required to load those properties.

Worth investigating @snakefoot 's comment about the complexity of the `SentryNLogOptions` class. If people are only using the ***NLog*** integration then ideally they'd be putting all of their Sentry config in one place, but maybe worth challenging that as it creates additional complexity (like this) elsewhere.

*Originally posted by @snakefoot in *[*#3680*]()

> Think the [Sentry.NLog]() project should update to NLog v5.2.2 (or newer).
>
> * See also: [https://nlog-project.org/2023/05/30/nlog-5-2-trim-warnings.html]()
> *
>
> And then you should provide a registration-method, that marks the relevant types in Sentry.NLog to not be trimmed (This already happens for all types inside NLog):
>
> ```c#
> NLog.LogManager.Setup().SetupExtensions(ext => {
> ext.RegisterTarget();
> ext.RegisterType();
> });
> ```
>
> You should probably avoid mixing options that are not intended to be assigned from NLog-configuration-file. Maybe SentryNLogOptions should not inherit from SentryOptions. But should instead just expose the properties that are intended to be assigned from NLog-configuration-file. Then you could have a property in SentryNLogOptions marked like this:
>
> ```c#
> [NLogConfigurationItem]
> public class SentryNLogOptions
> {
> [NLogConfigurationIgnoreProperty]
> public SentryOptions SentryOptions { get; } = new SentryOptions();
>
> public int ShutdownTimeoutSeconds
> {
> get => (int)SentryOptions.ShutdownTimeout.TotalSeconds;
> set => SentryOptions.ShutdownTimeout = TimeSpan.FromSeconds(value);
> }
> }
> ```
>
> Notice the AOT-issues that NLog v6 will be fixing is removing the dependency on RegEx and XmlReader and ExpressionTrees, since they include code-generation-abilities and there is no JIT-compiler included with pure AOT-builds.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.