-
Notifications
You must be signed in to change notification settings - Fork 239
logging changes #3087
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
Closed
Closed
logging changes #3087
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e61fe27
trying some logging stuff
deepchoudhery 85b80ff
init, trying a simple AnsiConsoleLogger
deepchoudhery 8c12b32
cleaned up logging, setup a very simple AnsiConsoleLogger
deepchoudhery 0c0c2c7
minor cleanup
deepchoudhery 3bdc49f
fixing build
deepchoudhery 6a88f87
using Serilog, added AnsiConsoleSink
deepchoudhery e8e60c4
revert Versions.props
deepchoudhery f326ef7
adding Serilog dlls for signing
deepchoudhery 57bc8eb
fixes based on PR feedback
deepchoudhery 6bda1bd
check for "true" when checking for LAUNCHED_BY_DOTNET_SCAFFOLD
deepchoudhery 7ce15c8
addressed all PR feedback
deepchoudhery 97eb82c
fix Versions.props
deepchoudhery 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
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
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
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
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
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
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
43 changes: 43 additions & 0 deletions
43
src/dotnet-scaffolding/Microsoft.DotNet.Scaffolding.Core/Logging/AnsiConsoleSink.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 |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| using Microsoft.DotNet.Scaffolding.Core.ComponentModel; | ||
| using Microsoft.DotNet.Scaffolding.Internal.Shared; | ||
| using Serilog.Core; | ||
| using Serilog.Events; | ||
| using Spectre.Console; | ||
|
|
||
| namespace Microsoft.DotNet.Scaffolding.Core.Logging; | ||
|
|
||
| public class AnsiConsoleSink : ILogEventSink | ||
| { | ||
| public void Emit(LogEvent logEvent) | ||
| { | ||
| //LAUNCHED_BY_DOTNET_SCAFFOLD should be "true", or some other value. "true" indicates being launched by dotnet-scaffold. | ||
| bool isLaunchedByDotnetScaffold = EnvironmentHelpers.GetEnvironmentVariableAsBool(ScaffolderConstants.LAUNCHED_BY_DOTNET_SCAFFOLD); | ||
| var formattedMessage = FormatMessage(logEvent.Level, logEvent.RenderMessage()); | ||
| if (isLaunchedByDotnetScaffold && (Console.IsOutputRedirected || Console.IsErrorRedirected)) | ||
| { | ||
| // Output plain markup for main app to handle | ||
| AnsiConsole.WriteLine(formattedMessage); | ||
| } | ||
| else | ||
| { | ||
| // Render colored output directly | ||
| AnsiConsole.MarkupLine(formattedMessage); | ||
| } | ||
| } | ||
|
|
||
| private string FormatMessage(LogEventLevel level, string message) | ||
| { | ||
| return level switch | ||
| { | ||
| LogEventLevel.Verbose => $"[gray]{message}[/]", | ||
| LogEventLevel.Debug => $"[gray]{message}[/]", | ||
| LogEventLevel.Information => $"[default]{message}[/]", | ||
| LogEventLevel.Warning => $"[yellow]{message}[/]", | ||
| LogEventLevel.Error => $"[red]{message}[/]", | ||
| LogEventLevel.Fatal => $"[bold red]{message}[/]", | ||
| _ => message | ||
| }; | ||
| } | ||
| } |
27 changes: 0 additions & 27 deletions
27
src/dotnet-scaffolding/Microsoft.DotNet.Scaffolding.Core/Logging/CleanConsoleFormatter.cs
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
...net-scaffolding/Microsoft.DotNet.Scaffolding.Core/Logging/CleanConsoleFormatterOptions.cs
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
src/dotnet-scaffolding/Microsoft.DotNet.Scaffolding.Core/Logging/ConsoleLoggerExtensions.cs
This file was deleted.
Oops, something went wrong.
11 changes: 8 additions & 3 deletions
11
...et-scaffolding/Microsoft.DotNet.Scaffolding.Core/Microsoft.DotNet.Scaffolding.Core.csproj
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
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
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.