-
Notifications
You must be signed in to change notification settings - Fork 25k
Remove problematic factory.create.logger /7 #30249
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
Merged
Merged
Changes from 10 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b48919a
Remove problematic factory.create.logger /7
Rick-Anderson 0f1fc45
Remove problematic factory.create.logger /7
Rick-Anderson c2cff2d
Remove problematic factory.create.logger /7
Rick-Anderson a3c8638
Update aspnetcore/fundamentals/logging/index/samples/6.x/WebLog/Progr…
Rick-Anderson c49cf44
React to feedback
Rick-Anderson 1e7d11c
React to feedback
Rick-Anderson 0d5a3fd
React to feedback
Rick-Anderson 814b79f
React to feedback
Rick-Anderson bac2b3d
React to feedback
Rick-Anderson 3800d37
React to feedback
Rick-Anderson 9be3293
React to feedback
Rick-Anderson 6fa4c50
Apply suggestions from code review
Rick-Anderson cf690e6
React to feedback
Rick-Anderson 7245cc3
React to feedback
Rick-Anderson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 41 additions & 19 deletions
60
aspnetcore/fundamentals/logging/index/samples/6.x/WebLog/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,58 +1,80 @@ | ||
| #define APP3 // FIRST SECOND APP3 | ||
| #define FIRST // FIRST SECOND APP3 APP4 | ||
| #if NEVER | ||
| #elif FIRST | ||
| #region snippet1 | ||
| // <snippet1> | ||
| var builder = WebApplication.CreateBuilder(args); | ||
|
|
||
| var logger = LoggerFactory.Create(config => | ||
| { | ||
| config.AddConsole(); | ||
| }).CreateLogger("Program"); | ||
| // Configure logging with AddConsole() | ||
| builder.Logging.AddConsole(); | ||
|
|
||
| var app = builder.Build(); | ||
|
|
||
| app.MapGet("/", () => "Hello World!"); | ||
|
|
||
| app.MapGet("/Test", async context => | ||
| app.MapGet("/Test", async (ILogger logger, HttpResponse response) => | ||
Rick-Anderson marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| logger.LogInformation("Testing logging in Program.cs"); | ||
| await context.Response.WriteAsync("Testing"); | ||
| await response.WriteAsync("Testing"); | ||
| }); | ||
|
|
||
| app.Run(); | ||
| #endregion | ||
| // </snippet1> | ||
| #elif SECOND | ||
| #region snippet2 | ||
| // <snippet2> | ||
| using Microsoft.Extensions.Logging.Console; | ||
|
|
||
| var builder = WebApplication.CreateBuilder(args); | ||
|
|
||
| using var loggerFactory = LoggerFactory.Create(builder => | ||
| { | ||
| builder.AddSimpleConsole(i => i.ColorBehavior = LoggerColorBehavior.Disabled); | ||
| }); | ||
|
|
||
| var logger = loggerFactory.CreateLogger<Program>(); | ||
| // Configure logging with AddSimpleConsole | ||
| builder.Logging.AddSimpleConsole(i => i.ColorBehavior = LoggerColorBehavior.Disabled); | ||
|
|
||
| var app = builder.Build(); | ||
|
|
||
| app.MapGet("/", () => "Hello World!"); | ||
|
|
||
| app.MapGet("/Test", async context => | ||
Rick-Anderson marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| var logger = app.Logger; // Access the configured logger directly | ||
| logger.LogInformation("Testing logging in Program.cs"); | ||
| await context.Response.WriteAsync("Testing"); | ||
| }); | ||
|
|
||
| app.Run(); | ||
| #endregion | ||
|
|
||
| // </snippet2> | ||
| #elif APP3 | ||
| #region snippet3 | ||
| // <snippet3> | ||
| var builder = WebApplication.CreateBuilder(args); | ||
| var app = builder.Build(); | ||
| app.Logger.LogInformation("Adding Routes"); | ||
| app.MapGet("/", () => "Hello World!"); | ||
| app.Logger.LogInformation("Starting the app"); | ||
| app.Run(); | ||
| #endregion | ||
| // </snippet3> | ||
| #elif APP4 | ||
| // <snippet4> | ||
| var builder = WebApplication.CreateBuilder(args); | ||
|
|
||
| builder.Logging.AddSimpleConsole(options => | ||
| { | ||
| options.IncludeScopes = true; | ||
| }); | ||
|
|
||
| builder.Logging.Configure(options => | ||
| { | ||
| options.ActivityTrackingOptions = ActivityTrackingOptions.SpanId | ||
| | ActivityTrackingOptions.TraceId | ||
| | ActivityTrackingOptions.ParentId | ||
| | ActivityTrackingOptions.Baggage | ||
| | ActivityTrackingOptions.Tags; | ||
| }); | ||
| var app = builder.Build(); | ||
|
|
||
| app.MapGet("/", () => "Hello World!"); | ||
|
|
||
| app.Run(); | ||
| // </snippet4> | ||
| #elif APP5 | ||
| // <snippet5> | ||
| // </snippet5> | ||
| #endif | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@noahfalk @cijothomas who can review this NOTE: and suggest more accurate wording. Much of it was written by the ChatGPT plugin for VS.
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 text of the note seems quite accurate to me, but the note itself feels disconnected from the text around it. Assuming that we make the other changes in the snippets then this docs page will have no references to using LoggerFactory.Create and I think the note can be omitted. I am guessing a lot of the confusion was occurring because some sample snippets were using LoggerFactory.Create and people would copy those snippets.
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.
+1
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.
(Very impressed with ChatGPT's notes, btw!)
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.
@Rick-Anderson I suggest to remove this note. Its no longer needed, and having it there is probably confusing without any context.