https://pulumi.com logo
Title
w

worried-city-86458

05/19/2021, 9:01 PM
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:
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
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

tall-librarian-49374

05/20/2021, 5:46 AM
This makes sense to me. Open an issue? (PR?)
👍 1
w

worried-city-86458

05/20/2021, 7:53 AM
b

bored-oyster-3147

05/20/2021, 10:46 AM
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

worried-city-86458

05/20/2021, 10:59 AM
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:
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