Sustainsys / Saml2

Saml2 Authentication services for ASP.NET
Other
945 stars 605 forks source link

How to prevent specified ILoggerAdapter from being thrown away #1396

Closed RobSiklos closed 10 months ago

RobSiklos commented 1 year ago

Version: Sustainsys.Saml2.AspNetCore2 - 2.9.0

Description In my ConfigureServices method, I am calling something like this:

    authBuilder.AddSaml2(options => {
     options.SPOptions.Logger = new MyCustomLoggerAdapter();
    });

This used to work (maybe in an older version on .NET 4.x), but now (.NET 6), it seems like my logger adapter isn't being used at all.

It seems that in https://github.com/Sustainsys/Saml2/blob/329306180c708fa60428e424aa3a69c149166917/Sustainsys.Saml2.AspNetCore2/PostConfigureSaml2Options.cs#L48-L56, the logger I've set on the SPOptions is being discarded and replaced with something from the factory, or a null logger.

What am I doing wrong? How can I make it so that the logger adapter I've specified on the SPOptions is used?

Thanks in advance.

AndersAbel commented 1 year ago

You've found a bug. The assumption in Asp.Net Core is that the Asp.Net Core logging infrastructure should be used. The logger adapter model is more intended to use for the HttpModule, the Mvc controller or the Owin package.

But I'll mark it as a bug, but don't hold your breath waiting for a fix.

A workaround is to add another IPostConfigureOptions after the call to AddSaml2. That should make your code run after the library code.