-
Notifications
You must be signed in to change notification settings - Fork 244
Make AddFilter chainable, add some doc comments, add UseConfiguration… #597
Conversation
| { "SampleApp.Program", LogLevel.Debug } | ||
| }); | ||
| var factory = new LoggerFactory() | ||
| .UseConfiguration(loggingConfiguration.GetSection("Logging")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure of this name. It kind of implies that you are configuring the factory, like adding providers, instead of just filtering.
|
@Eilon Some doc comments |
| /// <summary> | ||
| /// Replaces the <see cref="IConfiguration"/> used for filtering. | ||
| /// </summary> | ||
| /// <param name="configuration">The replacing configuration.</param> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new configuration to use. ?
| public void AddFilter(string providerName, string categoryName, Func<LogLevel, bool> filter) | ||
| /// <summary> | ||
| /// Adds a filter that applies to <paramref name="providerName"/> and <paramref name="categoryName"/> with the given | ||
| /// <paramref name="filter"/>, returning true means allow log through, false means reject log. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the , returning ... section because it's just describing the parameter. Put that text in the description of how ti implement the filter parameter.
| } | ||
|
|
||
| /// <summary> | ||
| /// Replaces the <see cref="IConfiguration"/> used for filtering. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit late on the design here, but why does this replace the configuration used for filtering? What if I have 2 sets of config that I want to use from 2 different sections? This seems to me like it should all be additive, always.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think usage will mostly be factory.UseConfiguration(config.GetSection("Logging"))
with the config having:
{
"OtherStuff": {
},
"Logging": {
"LogLevel": {
"System": "Trace"
}
}
}When would you want to use multiple sections?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would we specifically disallow it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok punting on this now; let's log a bug to track this discussion.
| var writes = provider.Sink.Writes; | ||
| Assert.Equal(1, writes.Count); | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bunch of code changed in this PR - should there not be more tests for this? E.g. the new extension methods, the new UseConfiguration() method, etc.
15aacad to
1f8e600
Compare
|
🆙 📅 |
|
Need to do aspnet/MetaPackages#45 and |
| public void AddFilter(string providerName, Func<string, LogLevel, bool> filter) | ||
| /// <summary> | ||
| /// Adds a filter that applies to <paramref name="providerName"/> with the given | ||
| /// <paramref name="filter"/>, returning true means allow log through, false means reject log. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are two separate sentences. Also, the second part of the sentence (line 2) really just applies to the filter param, so should put that comment there. I think this was corrected in the previous comments, so I recommend using that same pattern for all of them.
|
|
||
| /// <summary> | ||
| /// Adds a filter that applies to <paramref name="providerName"/> with the given | ||
| /// <paramref name="filter"/>, returning true means allow log through, false means reject log. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See earlier comments, apply to the extension methods as well.
|
|
||
| namespace Microsoft.Extensions.Logging | ||
| { | ||
| public static class LoggerFactoryExtensions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a class-level doc comment as well. Could be as simple as something like: https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNetCore.Mvc/MvcServiceCollectionExtensions.cs#L15-L17
| /// <param name="categoryName">The name of the logger category.</param> | ||
| /// <param name="minLevel">The minimum <see cref="LogLevel"/> that logs from | ||
| /// <paramref name="providerName"/> and <paramref name="categoryName"/> are allowed.</param> | ||
| public static LoggerFactory AddFilter(this LoggerFactory factory, string providerName, string categoryName, LogLevel minLevel) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
General question: Why are some of these extension methods, but some are methods on LoggerFactory itself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Performance mainly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wuh?? Performance of what?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Talked in person, the perf is about optimizing the instance methods because they can do smarter stuff w/ data structures. But then there's no reason to have extension methods, they might as well all be instance.
| writes = loggerProvider.Sink.Writes; | ||
| Assert.Equal(1, writes.Count); | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Umm... missing something here??? 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hahaha! Maybe thats why it passes ;)
| /// <param name="filter">The filter that applies to logs for <paramref name="providerName"/> and <paramref name="categoryName"/>, | ||
| /// returning true means allow log through, false means reject log.</param> | ||
| /// <returns>The <see cref="LoggerFactory"/> so that additional calls can be chained.</returns> | ||
| public LoggerFactory AddFilter(string providerName, string categoryName, Func<LogLevel, bool> filter) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a null check for filter?
| // Assert | ||
| writes = loggerProvider.Sink.Writes; | ||
| Assert.Equal(1, writes.Count); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do all the filter methods (whether instance methods or extension methods) have at least one or two tests each? (For whatever interesting combinations of params they have.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, made sure they all have at least 1 test. I wanted to do a programmatic way of testing all the filters with each other etc. but it was going to be complex and crazy so...
1f8e600 to
0fb4b65
Compare
5359618 to
8c0cde4
Compare
… to LoggerFactory