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

ASP.NET ILogger adapter #35

Open
dzmitry-lahoda opened this issue Feb 18, 2020 · 1 comment
Open

ASP.NET ILogger adapter #35

dzmitry-lahoda opened this issue Feb 18, 2020 · 1 comment

Comments

@dzmitry-lahoda
Copy link

Could we have extension method onto TraceSource which exactly same as ILogger, but with no dependency on ASP.NET. So kind of reference free drop in replacement.

@sgryphon
Copy link
Owner

I'm not really sure what this means.

Usually the Adapter pattern is used to adapt from one pattern to another. i.e. public class TraceSourceAdapterLogger : ILogger { public TraceSourceAdapterLogger(TraceSource traceSource)...

However, this already exists, TraceSourceLoggerProvider.

If you configure TraceSourceLoggerProvider for a modern app that is using Microsoft.Extensions.Logging ILogger, then it will write through to the trace source (actually a hierarchy of trace sources, based on the name), and then through to any attached listeners, including the listeners from Essential Diagnostics.

However there is no automatic configuration, i.e. it won't load XML property settings, etc. This means you need to wire everything up in code. You can do this at the host level and then inject, or could even use reflection to load dynamically, but would have to do all that yourself.

I would just use ILogger, and I have already ported some of the TraceListeners across to equivalent LoggerProviders in my Essential.Logging project.

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

No branches or pull requests

2 participants