Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

logging changes #3087

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft

Conversation

deepchoudhery
Copy link
Member

@deepchoudhery deepchoudhery commented Nov 20, 2024

changes :

  • removed CleanConsoleFormatter, CleanConsoleFormatterOptions, ConsoleLoggerExtensions
  • added AnsiConsoleSink
    • check if being invoked by dotnet-scaffold and colorize output accordingly (let dotnet-scaffold do it if that's where output is going)
  • configure Serilogger in ScaffolderRunnerBuilder
  • verbose logging and logging to file set through command line flags using dotnet-scaffold
    • --verbose and --log-to-file
    • LAUNCHED_BY_DOTNET_SCAFFOLD gets set in CommandExecuteFlowStep and then read in ScaffolderRunnerBuilder to configure the LoggerConfiguration

all the different options and ways to enable logging:
dotnet-scaffold

  • use option --verbose (bool option):
    • enables verbose logging which corresponds to logging level Trace.
    • adds environment variable ENABLE_VERBOSE_LOGGING to "true".
  • use option --log-to-file (bool option):
    • enables logging to file regardless of logging level (Information or Trace are the only options currently)
    • adds environment variable LOG_TO_FILE to "true".

dotnet-scaffold-aspnet/aspire : env vars above can be set manually (if running standalone) or through dotnet-scaffold options

  • verbose logging :
    • check for ENABLE_VERBOSE_LOGGING env var
    • if enabled, set minimum logging level to Verbose using LoggerConfiguration().MinimumLevel.Verbose()
    • ILogger.LogDebug and ILogger.LogTrace are only enabled (and colorized using the AnsiConsoleSink
  • logging to file :
    • check for LOG_TO_FILE env var
    • use/create .\%USERPROFILE%\.dotnet-scaffold\.logs folder at the current location and add '.log' logs to this location
    • in the format 'dotnet-scaffold-YYYY-mm-DD_hh-MM.log`
    • scenarios :
      • files are created per execution. The timestamp will be from the minute logging is setup in the ScaffolderRunnerBuilder (this might differ from when dotnet-scaffold execution starts due to interactivity and time taken to reach this code block)
      • on consequent executions in the same minute, log files postfixed with -X with X being a number.
      • timestamp is local system time (using DateTime.Now) since its the .NET standard and more uniform.
      • files created with .log extension (the .NET standard).

@deepchoudhery deepchoudhery requested a review from tlmii November 20, 2024 03:35
@deepchoudhery deepchoudhery self-assigned this Nov 20, 2024
@tlmii
Copy link
Member

tlmii commented Dec 5, 2024

@deepchoudhery Could you add some examples of how the logging options would be used by the end user in the PR description? They seem pretty straightforward, but I want to make sure.

@deepchoudhery deepchoudhery changed the title initial logging changes logging changes Dec 6, 2024
@deepchoudhery deepchoudhery marked this pull request as ready for review December 6, 2024 23:48
@deepchoudhery deepchoudhery force-pushed the dev/decho/update-dotnet-scaffold-logging branch from 9692f55 to ec1580d Compare December 7, 2024 00:00
@deepchoudhery deepchoudhery force-pushed the dev/decho/update-dotnet-scaffold-logging branch from b018ca9 to 9392248 Compare December 11, 2024 01:25
@deepchoudhery deepchoudhery force-pushed the dev/decho/update-dotnet-scaffold-logging branch from 9392248 to 7ce15c8 Compare December 13, 2024 21:11
@deepchoudhery deepchoudhery marked this pull request as draft December 30, 2024 20:06
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants