pulumi / pulumi-dotnet

.NET support for Pulumi
Apache License 2.0
28 stars 25 forks source link

Allow fallback for Pulumi.Log when used outside a Pulumi run #152

Open thecodetinker opened 1 year ago

thecodetinker commented 1 year ago

Hello!

Issue details

Our Pulumi C# code contains a number of helper classes, for example one that calculates IP CIDR Ranges. These have unit tests independent of Pulumi, and need to do some logging. The nice thing to do would be to use Pulumi.Log in the code, however this fails during execution outside of a Pulumi stack.

System.InvalidOperationException
Trying to acquire Deployment.Instance before 'Run' was called.

As far as I can tell, there is no way to tell whether or not Pulumi is running or not so it's hard to even fall back to Console. The 'proper' answer may be to start injecting ILogger with some kind of dynamic configuration, but this feels a little bit like overkill when it would be nice to just he Pulumi.Log everywhere but have it behave itself when called outside of Pulumi run.

Affected area/feature

Logging.

dixler commented 1 year ago

Hi, thanks for filing this. Will discuss with the team.