Skip to content

Conversation

pakrym
Copy link

@pakrym pakrym commented Dec 13, 2018

Adds the LoggerFactory.Create that simplifies LoggerFactory creation in cases where dependency injection is not used in the application.

So the pattern becomes:

var loggerFactory = LoggerFactory.Create(builder => 
    builder.AddEventSourceLogger()
           .AddConsole()
           .AddFilter(...));

Fixes: #615


<Reference Include="Microsoft.Extensions.Configuration.Binder" />
<Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions" />
<Reference Include="Microsoft.Extensions.DependencyInjection" />
Copy link
Member

@davidfowl davidfowl Dec 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is slightly unfortunate. But not the end of the world I guess.

public bool ShouldDispose;
}

private class DisposingLoggerFactory: ILoggerFactory
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fact that we need to hold onto the container means all of the sample code is sorta busted

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Busted how?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you’re saying we don’t need to dispose the service provider?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this wrapper exist to begin with?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To dispose ILoggerProviders created by DI

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn’t disposing the factory do that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see it wouldn’t. That makes the current usage without this API leaky.

Copy link
Author

@pakrym pakrym Dec 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't dispose the service provider - yes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m taking about examples that you would use today (even in our samples)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed a sample fix.

@pakrym pakrym merged commit 1414cac into master Dec 13, 2018

<Reference Include="Microsoft.Extensions.Configuration.Binder" />
<Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions" />
<Reference Include="Microsoft.Extensions.DependencyInjection" />

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that this change caused these failures in my PR build. It actually showed up in your PR check too, but as a warning instead of an error.

@natemcmaster 1. Is the proper solution here (assuming it is an approved breaking change) to edit this line? 2. Should this kind of change be a warning or an error?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ryanbrandenburg does your PR invoke build with --warnaserror?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's what Arcade defaults to. We can certainly override that anywhere (or everywhere), but I thought I'd ask since this seems like the kind of thing we might want to fail a build (even if it's just so we can document that this was an intended break).

@natemcmaster natemcmaster deleted the pakrym/LF-Create branch December 13, 2018 22:09
maryamariyan pushed a commit to maryamariyan/runtime that referenced this pull request Feb 28, 2020
maryamariyan pushed a commit to maryamariyan/runtime that referenced this pull request Mar 2, 2020
maryamariyan pushed a commit to maryamariyan/runtime that referenced this pull request Mar 11, 2020
maryamariyan pushed a commit to maryamariyan/runtime that referenced this pull request Mar 27, 2020
@ghost ghost locked as resolved and limited conversation to collaborators May 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants