Can't find Logs in StackDriver
odytrice opened this issue · 5 comments
Hi, I configured the application like shown below
appsettings.yaml
Serilog:
MinimumLevel:
Default: Information
Override:
Microsoft: Information
System: Warning
Enrich:
- FromLogContext
- WithMachineName
- WithProcessId
- WithThreadId
WriteTo:
- Name: Console
appsettings.env.yaml
Using: [ "Serilog.Sinks.GoogleCloudLogging" ]
WriteTo:
- Name: GoogleCloudLogging
Args:
ProjectId: <projectid>
UseJsonOutput: true
ResourceType: k8s_cluster
ResourceLabels:
ProjectId: <projectid>
Location: europe-west1-d
ClusterName: <cluster-name>
I also have GOOGLE_APPLICATION_CREDENTIALS environment variable set to a google credential json file
Is there a way to tell what is going on? or what I'm getting wrong?
Tried downgrading and got this
Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.MissingMethodException: Method not found: 'Google.Cloud.Logging.V2.LoggingServiceV2Client Google.Cloud.Logging.V2.LoggingServiceV2Client.Create(Google.Api.Gax.Grpc.ServiceEndpoint, Google.Cloud.Logging.V2.LoggingServiceV2Settings)'.
at Serilog.Sinks.GoogleCloudLogging.GoogleCloudLoggingSink..ctor(GoogleCloudLoggingSinkOptions sinkOptions, MessageTemplateTextFormatter messageTemplateTextFormatter, Int32 batchSizeLimit, TimeSpan period)
at Serilog.Sinks.GoogleCloudLogging.GoogleCloudLoggingSinkExtensions.GoogleCloudLogging(LoggerSinkConfiguration loggerConfiguration, GoogleCloudLoggingSinkOptions sinkOptions, Nullable`1 batchSizeLimit, Nullable`1 period, String outputTemplate)
at Serilog.Sinks.GoogleCloudLogging.GoogleCloudLoggingSinkExtensions.GoogleCloudLogging(LoggerSinkConfiguration loggerConfiguration, String projectId, String resourceType, String logName, Dictionary`2 labels, Dictionary`2 resourceLabels, Boolean useSourceContextAsLogName, Boolean useJsonOutput, String googleCredentialJson, String serviceName, String serviceVersion, Nullable`1 batchSizeLimit, Nullable`1 period, String outputTemplate)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Serilog.Settings.Configuration.ConfigurationReader.CallConfigurationMethods(ILookup`2 methods, IList`1 configurationMethods, Object receiver)
at Serilog.Settings.Configuration.ConfigurationReader.Configure(LoggerConfiguration loggerConfiguration)
at Serilog.Configuration.LoggerSettingsConfiguration.Settings(ILoggerSettings settings)
It's better to use the latest libraries since the GCP APIs have changed recently. Did you use the TestWeb project to see if that creates logs?
As far as I can test, the GRPC logging calls are made and the issue seems to be with GCP's API either not accepting or not showing them in the UI. I don't have much to go on since thesolutions I use have always worked so far and nobody has offered a reproducible sample.
If the TestWeb works for you, then I recommend copying the 3 code files into your project directly and running it that way with the debugger to see where the error might be.
I cloned the repository but it hangs whenever I try to restore packages
dotnet version: 3.1.201
I managed to resolve it. Here are the list of things I did
-
I think the configuration was case sensitive so I had to correct that to match what was in the docs for example I changed
ProjectId
toprojectID
e.t.c. -
I needed to add the
LogWriter
permission to the Service Account which I somehow missed to do -
I had to label the logs correctly
I ended up with something like this
Using: [ "Serilog.Sinks.GoogleCloudLogging" ]
WriteTo:
- Name: GoogleCloudLogging
Args:
projectID: <project-id>
useJsonOutput: true
resourceType: k8s_container
resourceLabels:
project_id: <project-id>
cluster_name: <clustername>
location: <location>
namespace_name: <k8s-namespace>
container_name: <k8s-deployment-name>
Thanks for the help