Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Conversation

@BrennanConroy
Copy link
Member

… to LoggerFactory

{ "SampleApp.Program", LogLevel.Debug }
});
var factory = new LoggerFactory()
.UseConfiguration(loggingConfiguration.GetSection("Logging"))
Copy link
Member

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.

@BrennanConroy BrennanConroy requested a review from pakrym April 13, 2017 16:17
@BrennanConroy
Copy link
Member Author

@Eilon Some doc comments

/// <summary>
/// Replaces the <see cref="IConfiguration"/> used for filtering.
/// </summary>
/// <param name="configuration">The replacing configuration.</param>
Copy link
Contributor

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.
Copy link
Contributor

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.
Copy link
Contributor

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.

Copy link
Member Author

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?

Copy link
Contributor

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?

Copy link
Contributor

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);
}

Copy link
Contributor

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.

@BrennanConroy
Copy link
Member Author

🆙 📅

@BrennanConroy
Copy link
Member Author

Need to do aspnet/MetaPackages#45 and Remove passing logging section by default in hosting after this change.

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.
Copy link
Contributor

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.
Copy link
Contributor

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
Copy link
Contributor

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)
Copy link
Contributor

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

Performance mainly

Copy link
Contributor

Choose a reason for hiding this comment

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

Wuh?? Performance of what?

Copy link
Contributor

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);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Umm... missing something here??? 😄

Copy link
Member Author

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)
Copy link
Contributor

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);
}
Copy link
Contributor

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.)

Copy link
Member Author

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...

@BrennanConroy BrennanConroy merged commit eecb8e2 into dev Apr 25, 2017
@BrennanConroy BrennanConroy deleted the brecon/fixup branch April 25, 2017 22:03
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.

5 participants