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

Custom/logger #18258

Merged
merged 11 commits into from
May 13, 2020
Merged

Custom/logger #18258

merged 11 commits into from
May 13, 2020

Conversation

Rick-Anderson
Copy link
Contributor

@Rick-Anderson Rick-Anderson commented May 11, 2020

Internal review URL

Public review:

  • Go to this DropBox link
  • In the upper right, select Download -> Direct download
  • Click on HTML files.

JuergenGutsch and others added 2 commits May 11, 2020 21:18
* Add a section in the docs aspnetcore/fundamentals/logging/index.md
* Add a sample at aspnetcore/fundamentals/logging/loggermessage/samples/3.1/CustomLogger
@Rick-Anderson
Copy link
Contributor Author

@JuergenGutsch please review the changed files and the public build.

cc @serpent5

@JuergenGutsch
Copy link
Contributor

@Rick-Anderson Awesome. Looks good from my perspective 👍 Many Thanks 😊

_logger.LogWarning("The Index action was just started");
_logger.LogError("Not really an error. Just to show the custom logger");
_logger.LogDebug("End Index action in the HomeController");
var routeInfo = ControllerContext.ToCtxString();
Copy link
Contributor

Choose a reason for hiding this comment

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

Much better 😄

@serpent5

This comment has been minimized.

@Rick-Anderson
Copy link
Contributor Author

@serpent5 I had similar thoughts on the organization, but I just wanted to get it in a more readable state.

I think your suggestions would be a nice improvement.

I'll ping the PU and see if they can do a quick review.

@Rick-Anderson Rick-Anderson marked this pull request as ready for review May 12, 2020 19:41
@Rick-Anderson
Copy link
Contributor Author

@BrennanConroy can you do a quick review or suggest a reviewer.

Copy link
Member

@BrennanConroy BrennanConroy left a comment

Choose a reason for hiding this comment

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

Looks pretty good


[!code-csharp[](index/samples/3.x/CustomLogger/Startup1.cs?name=snippet)]

The preceding code is verbose. The logger registration can be encapsulated, resulting in the following:
Copy link
Member

Choose a reason for hiding this comment

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

Most of this seems unneeded for this doc 🤷


[!code-csharp[](index/samples/3.x/CustomLogger/ColoredConsoleLogger/ColoredConsoleLoggerProvider.cs?name=snippet)]

In the preceding code, <xref:Microsoft.Build.Logging.LoggerDescription.CreateLogger*> creates a single instance of the `ColoredConsoleLogger` per category name and stores it in the <xref:System.Collections.Concurrent.ConcurrentDictionary`1>.
Copy link
Member

Choose a reason for hiding this comment

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

The ConcurrentDictionary xref seems broken


public bool IsEnabled(LogLevel logLevel)
{
return logLevel == _config.LogLevel;
Copy link
Member

Choose a reason for hiding this comment

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

Might want to use >= for the check instead

Copy link
Contributor

Choose a reason for hiding this comment

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

Not, if you want to set the color for a specific log level

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@JuergenGutsch reverted to your original code


[!code-csharp[](index/samples/3.x/CustomLogger/ColoredConsoleLogger/ColoredConsoleLoggerConfiguration.cs?name=snippet)]

The preceding code sets the default level to `Warning` and the color to `Yellow`. If the `EventId` is set to 0, we will log all events.
Copy link
Member

Choose a reason for hiding this comment

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

Why is the EventId being used to limit what is being logged?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's just a stupid demo, to show how to add a custom demo. Maybe some things doesn't really make sense. This logger is just coloring the log outputs.
In that case you are able to create an different colored output for a specific event id.

@BrennanConroy
Copy link
Member

+@JunTaoLuo in case you want to take a look

Co-authored-by: Brennan <brecon@microsoft.com>
@Rick-Anderson
Copy link
Contributor Author

@BrennanConroy can you review @serpent5 outline

@Rick-Anderson
Copy link
Contributor Author

@JuergenGutsch can you review my last commit?

@@ -22,7 +22,7 @@ public IDisposable BeginScope<TState>(TState state)

public bool IsEnabled(LogLevel logLevel)
{
return logLevel == _config.LogLevel;
return logLevel >= _config.LogLevel;
Copy link
Contributor

Choose a reason for hiding this comment

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

As mentioned in a comment of the review by @BrennanConroy this would enable the the output for a log level higher or equal to the configured one, instead of a specific one. This should be reflected in the text.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I call that out in the text.

The preceding code:

* Creates a logger instance per category name.
* Checks `logLevel == _config.LogLevel` in `IsEnabled`, so each `logLevel` has a unique logger. Generally, loggers should also be enabled for all higher log levels:
Copy link
Contributor

@JuergenGutsch JuergenGutsch May 13, 2020

Choose a reason for hiding this comment

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

Checks logLevel == _config.LogLevel in IsEnabled

This doesn't match the code and the code snippet anymore, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@JuergenGutsch I reverted to your original code. The snippets are imported into the doc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@JuergenGutsch oops, forgot to push that change. It's fixed now

@Rick-Anderson Rick-Anderson merged commit 9ab5adf into master May 13, 2020
@Rick-Anderson Rick-Anderson deleted the custom/logger branch May 13, 2020 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants