manigandham / serilog-sinks-googlecloudlogging

Serilog sink that writes events to Google Cloud Logging
MIT License
41 stars 25 forks source link

Cant write logs to google - permissions issue #36

Closed avifatal closed 4 years ago

avifatal commented 4 years ago

Hi, I created a service account with stack driver admin permissions. (admin: in order to remove permissions noice) Downloaded the json file. and created the following config

var json = File.ReadAllText("google.json");       
var config = new GoogleCloudLoggingSinkOptions { 
         ProjectId = "prj-2496077", 
         UseJsonOutput = true,
          GoogleCredentialJson = json,
          LogName = "LogName",
          UseSourceContextAsLogName = true
 };
var log = new LoggerConfiguration().Enrich.FromLogContext()
         .WriteTo.GoogleCloudLogging(sinkOptions: config).Destructure.JsonNetTypes().CreateLogger();

the self log indicates:

2020-04-05T05:42:57.3170296Z Exception while emitting periodic batch from Serilog.Sinks.GoogleCloudLogging.GoogleCloudLoggingSink: Grpc.Core.RpcException: Status(StatusCode=PermissionDenied, Detail="The caller does not have permission")
   at Google.Api.Gax.Grpc.ApiCallRetryExtensions.<>c__DisplayClass0_0`2.<<WithRetry>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Serilog.Sinks.GoogleCloudLogging.GoogleCloudLoggingSink.EmitBatchAsync(IEnumerable`1 events)
   at Serilog.Sinks.PeriodicBatching.PeriodicBatchingSink.OnTick()

What am I missing? whats wrong with my config?

Thanks

avifatal commented 4 years ago

Found it. closing, I souldnt use stackdriver roles. I should use logging roles