googleapis / google-cloud-dotnet

Google Cloud Client Libraries for .NET
https://cloud.google.com/dotnet/docs/reference/
Apache License 2.0
917 stars 362 forks source link

Google.Cloud.Logging.NLog enable parameter #13196

Open neotrow opened 2 weeks ago

neotrow commented 2 weeks ago

Is your feature request related to a problem? Please describe. We use appsettings.{environment}.json to configure NLog. In the root appsettings.json we have a configured the GoogleStackdriver target. In the appsettings.{environment}.json we have configured the rules for NLog to write the logs to the correct places. In appsettings.Development.json we don't want to write to gcp stackdriver. But our code now throws an exception because there were no credentials configured during the initialisation phase.

Describe the solution you'd like We would appreciate an enable parameter that would skip the whole initialzion and maybe throw an exception if you try to write to gcp stack driver if this is set to false. Or alternativley have a skipCredentials parameter.

Describe alternatives you've considered Our alternative is to move the gcp stack driver target to the appsettings.{environment}.json instead of the root appsettings.json but this means we have it duplicated.

amanda-tarafa commented 2 weeks ago

NLog supports referencing configuration defined elsewhere, i.e. not as part of NLog configuration itself. See https://github.com/NLog/NLog/wiki/ConfigSetting-Layout-Renderer#configuration-syntax.

I think with this you can still configure the GoogleStackdriver target on appsettings.json, but as a standalone object, not as part of NLog configuration. Then on each of the appsettings.{environment}.json that you want to use GoogleStackdriver you configure NLog targets referencing the object defined in appsettings.json.

amanda-tarafa commented 1 week ago

@neotrow were you able to try my approach from the previous comment?