Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nullable parameters in ConfigurationExtensions #436

Open
bstordrup opened this issue Sep 12, 2024 · 2 comments
Open

Nullable parameters in ConfigurationExtensions #436

bstordrup opened this issue Sep 12, 2024 · 2 comments

Comments

@bstordrup
Copy link

In my appsettings.json, I have this WriteTo definition:

      {
        "Name": "Notepad",
        "Args": {
          "outputTemplate": "[{Timestamp:yyyy-MM-dd HH:mm:ss} {Level:u3}] CompanyId {VismaNetCompanyId} {Message:lj}{NewLine}{Exception}",
          "processCommandLineArg": "/SELog"
        }
      }

I have a SinkConfigurationExtensions method defined like this:

        public static LoggerConfiguration Notepad (
            this LoggerSinkConfiguration sinkConfiguration,
            LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
            string outputTemplate = _defaultNotepadOutputTemplate,
            IFormatProvider formatProvider = null,
            LoggingLevelSwitch levelSwitch = null,
            Func<Process> notepadProcessFinderFunc = null,
            string processCommandLineArg = "",
            object syncRoot = null,
            IConfiguration configuration = null)

This method is hit as expected.

But Roslyn triggers a CS86252: Cannot convert null literal to non-nullable reference type warning on it and suggests to declare it as nullable.

So changing the definition to

        public static LoggerConfiguration Notepad (
            this LoggerSinkConfiguration sinkConfiguration,
            IFormatProvider? formatProvider,
            LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
            string outputTemplate = _defaultNotepadOutputTemplate,
            LoggingLevelSwitch levelSwitch = null,
            Func<Process> notepadProcessFinderFunc = null,
            string processCommandLineArg = "",
            object syncRoot = null,
            IConfiguration configuration = null)

but now the method is not hit.

I'm using version 3.3.0 - is this an issue that has been fixed in a more recent version?

@nblumhardt
Copy link
Member

Hi @bstordrup - a lot has changed since v3.3, so I'd try updating. I don't think nullability annotations will influence the behavior of this package though, so I suspect the issue might be elsewhere.

If you still run into trouble, paring this down to a minimal repro would be the best way to guide us towards what needs fixing. Hope this helps!

@bstordrup
Copy link
Author

Ok. I will try to update and test. But I think the issue is related to finding ConfigurationExtension method candidates to call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants