The dotnet automation is logging with serilog, whi...
# dotnet
w
The dotnet automation is logging with serilog, which is great, but without setting
SourceContext
, which is used to configure logging per source.
I'm using
config.Development.yml
to configure logging:
Copy code
Serilog:
  MinimumLevel:
    Override:
      Microsoft: Information
      Microsoft.Hosting.Lifetime: Warning
  WriteTo:
    - Name: Seq
      Args:
        serverUrl: <http://localhost:5341>
But I can't control the dotnet automation api logging without a source context
This should be a matter of using
ILogger<T>
instead of
ILogger
where type
T
becomes the source context
Copy code
public sealed partial class DeployCommand : AsyncCommandBase<DeployCommand.Settings>
{
    public DeployCommand(IOptions<Config> options, ILogger<DeployCommand> logger, IServiceProvider serviceProvider) : base(options, logger)
    {
    }

    protected override async Task<int> OnExecuteAsync(CommandContext context, Settings settings)
    {
        Logger.LogInformation("Deploying resources...");
        using var totalTimeLogger = new ElapsedTimeLogger(Logger, "Deployed resources");
        ...
    }
}

public abstract class AsyncCommandBase<TSettings> : AsyncCommand<TSettings> where TSettings : CommandSettings
{
    protected AsyncCommandBase(IOptions<Config> options, ILogger logger)
    {
        Config = options.Value;
        Logger = logger;
    }

    protected Config Config { get; }
    protected ILogger Logger { get; }
}
@bored-oyster-3147 @tall-librarian-49374 ^
t
This makes sense to me. Open an issue? (PR?)
👍 1
w
b
AFAIK this is not an automation API thing. The core lib uses serilog so that is what you are seeing. Also it doesn’t use Microsoft.Extensions.Logging.ILogger. It uses a home rolled ILogger where the implementation is in Pulumi.Deployment.Logger which calls out to some static serilog methods.
w
Yeah I was just looking through the code and that's exactly right. Using the global shared serilog logger is messy but I can hack it to use a static
Serilog.Log.ForContext<Deployment>()
. It gets ugly when
PULUMI_DOTNET_LOG_VERBOSE
is defined as this creates a new logger which wipes my sinks.
I'll send a PR for further discussion...
Normally configuration of logging levels would be done via host configuration. I wire up everything in my generic host, so if pulumi interacted with that it wouldn't need to recreate the logger.
Meanwhile the quick fix in my PR will inject a source context of
Pulumi.Deployment
so I can control it with say:
Copy code
Serilog:
  MinimumLevel:
    Override:
      Pulumi.Deployment: Debug
(In this case I'll actually silence it by default because it makes my logs unreadable)
See the logging from a deploy is 99% noise from
Pulumi.Deployment