public static LoggerConfiguration GoogleCloudLogging( this LoggerSinkConfiguration loggerConfiguration, string projectId, string resourceType = null, string logName = null, Dictionary <string, string> labels = null, Dictionary <string, string> resourceLabels = null, bool useSourceContextAsLogName = true, bool useJsonOutput = false, string googleCredentialJson = null, string errorReportingServiceName = null, string errorReportingServiceVersion = null, int?batchSizeLimit = null, TimeSpan?period = null, string outputTemplate = null ) { var options = new GoogleCloudLoggingSinkOptions( projectId, resourceType, logName, labels, resourceLabels, useSourceContextAsLogName, useJsonOutput, googleCredentialJson, errorReportingServiceName, errorReportingServiceVersion ); return(loggerConfiguration.GoogleCloudLogging(options, batchSizeLimit, period, outputTemplate)); }
/// <summary> /// Writes log events to Google Cloud Platform Stackdriver Logging. /// </summary> /// <param name="loggerConfiguration">Logger sink configuration.</param> /// <param name="sinkOptions">Google Cloud Logging sink options.</param> /// <param name="batchSizeLimit">The maximum number of events to include in a single batch. The defailt is 100.</param> /// <param name="period">The time to wait between checking for event batches. The default is five seconds.</param> /// <param name="queueLimit">Maximum number of events in the queue. If not specified, uses an unbounded queue.</param> /// <param name="outputTemplate">A message template describing the format used to write to the sink.</param> /// <param name="restrictedToMinimumLevel">The minimum level for events passed through the sink. Ignored when <paramref name="levelSwitch"/> is specified.</param> /// <param name="levelSwitch">A switch allowing the pass-through minimum level to be changed at runtime.</param> /// <returns>Configuration object allowing method chaining.</returns> public static LoggerConfiguration GoogleCloudLogging( this LoggerSinkConfiguration loggerConfiguration, GoogleCloudLoggingSinkOptions sinkOptions, int?batchSizeLimit = null, TimeSpan?period = null, int?queueLimit = null, string outputTemplate = null, LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, LoggingLevelSwitch levelSwitch = null) { var messageTemplateTextFormatter = String.IsNullOrWhiteSpace(outputTemplate) ? null : new MessageTemplateTextFormatter(outputTemplate, null); var sink = new GoogleCloudLoggingSink( sinkOptions, messageTemplateTextFormatter ); var batchingOptions = new PeriodicBatchingSinkOptions { BatchSizeLimit = batchSizeLimit ?? 100, Period = period ?? TimeSpan.FromSeconds(5), QueueLimit = queueLimit }; var batchingSink = new PeriodicBatchingSink(sink, batchingOptions); return(loggerConfiguration.Sink(batchingSink, restrictedToMinimumLevel, levelSwitch)); }
public GoogleCloudLoggingSink(GoogleCloudLoggingSinkOptions sinkOptions, MessageTemplateTextFormatter messageTemplateTextFormatter, int batchSizeLimit, TimeSpan period) : base(batchSizeLimit, period) { if (sinkOptions.GoogleCredentialJson == null) { _client = LoggingServiceV2Client.Create(); } else { var googleCredential = GoogleCredential.FromJson(sinkOptions.GoogleCredentialJson); var channel = new Grpc.Core.Channel(LoggingServiceV2Client.DefaultEndpoint.Host, googleCredential.ToChannelCredentials()); _client = LoggingServiceV2Client.Create(channel); } _sinkOptions = sinkOptions; _resource = new MonitoredResource { Type = sinkOptions.ResourceType }; foreach (var kvp in _sinkOptions.ResourceLabels) { _resource.Labels[kvp.Key] = kvp.Value; } var ln = new LogName(sinkOptions.ProjectId, sinkOptions.LogName); _logName = ln.ToString(); _logNameToWrite = LogNameOneof.From(ln); _messageTemplateTextFormatter = messageTemplateTextFormatter; }
public GoogleCloudLoggingSink(GoogleCloudLoggingSinkOptions sinkOptions, MessageTemplateTextFormatter messageTemplateTextFormatter, int batchSizeLimit, TimeSpan period) : base(batchSizeLimit, period) { // logging client for google cloud apis // requires extra setup if credentials are passed as raw json text if (sinkOptions.GoogleCredentialJson == null) { _client = LoggingServiceV2Client.Create(); } else { var googleCredential = GoogleCredential.FromJson(sinkOptions.GoogleCredentialJson); var channel = new Grpc.Core.Channel(LoggingServiceV2Client.DefaultEndpoint.Host, googleCredential.ToChannelCredentials()); _client = LoggingServiceV2Client.Create(channel); } _sinkOptions = sinkOptions; _logFormatter = new LogFormatter(_sinkOptions, messageTemplateTextFormatter); _resource = new MonitoredResource { Type = sinkOptions.ResourceType }; foreach (var kvp in _sinkOptions.ResourceLabels) { _resource.Labels[kvp.Key] = kvp.Value; } var ln = new LogName(sinkOptions.ProjectId, sinkOptions.LogName); _logName = ln.ToString(); _logNameToWrite = LogNameOneof.From(ln); _serviceNameAvailable = !String.IsNullOrWhiteSpace(_sinkOptions.ServiceName); }
public GoogleCloudLoggingSink(GoogleCloudLoggingSinkOptions sinkOptions, MessageTemplateTextFormatter messageTemplateTextFormatter, int batchSizeLimit, TimeSpan period) : base(batchSizeLimit, period) { _client = LoggingServiceV2Client.Create(); _sinkOptions = sinkOptions; _resource = new MonitoredResource { Type = sinkOptions.ResourceType }; var ln = new LogName(sinkOptions.ProjectId, sinkOptions.LogName); _logName = ln.ToString(); _logNameToWrite = LogNameOneof.From(ln); _messageTemplateTextFormatter = messageTemplateTextFormatter; }
public static LoggerConfiguration GoogleCloudLogging(this LoggerSinkConfiguration loggerConfiguration, GoogleCloudLoggingSinkOptions sinkOptions, int?batchSizeLimit = null, TimeSpan?period = null, string outputTemplate = null) { var messageTemplateTextFormatter = String.IsNullOrWhiteSpace(outputTemplate) ? null : new MessageTemplateTextFormatter(outputTemplate, null); var sink = new GoogleCloudLoggingSink( sinkOptions, messageTemplateTextFormatter, batchSizeLimit ?? 100, period ?? TimeSpan.FromSeconds(5) ); return(loggerConfiguration.Sink(sink)); }
/// <summary> /// Overload that accepts all configuration settings as parameters to allow configuration in files using serilog-settings-configuration package. /// This method creates a GoogleCloudLoggingSinkOptions and calls the standard constructor above. /// </summary> /// <returns>Configuration object allowing method chaining.</returns> public static LoggerConfiguration GoogleCloudLogging( this LoggerSinkConfiguration loggerConfiguration, string projectId = null, string resourceType = null, string logName = null, Dictionary <string, string> labels = null, Dictionary <string, string> resourceLabels = null, bool useSourceContextAsLogName = true, bool useJsonOutput = false, string googleCredentialJson = null, string serviceName = null, string serviceVersion = null, int?batchSizeLimit = null, TimeSpan?period = null, int?queueLimit = null, string outputTemplate = null, LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, LoggingLevelSwitch levelSwitch = null ) { var options = new GoogleCloudLoggingSinkOptions( projectId, resourceType, logName, labels, resourceLabels, useSourceContextAsLogName, useJsonOutput, googleCredentialJson, serviceName, serviceVersion ); return(loggerConfiguration.GoogleCloudLogging( options, batchSizeLimit, period, queueLimit, outputTemplate, restrictedToMinimumLevel, levelSwitch )); }
public GoogleCloudLoggingSink(GoogleCloudLoggingSinkOptions sinkOptions, MessageTemplateTextFormatter messageTemplateTextFormatter, int batchSizeLimit, TimeSpan period) : base(batchSizeLimit, period) { _sinkOptions = sinkOptions; // logging client for google cloud apis // requires extra setup if credentials are passed as raw json text if (sinkOptions.GoogleCredentialJson == null) { _client = LoggingServiceV2Client.Create(); } else { var googleCredential = GoogleCredential.FromJson(sinkOptions.GoogleCredentialJson); var channel = new Grpc.Core.Channel(LoggingServiceV2Client.DefaultEndpoint.Host, googleCredential.ToChannelCredentials()); _client = LoggingServiceV2Client.Create(channel); } // retrieve current environment details (gke/gce/appengine) from google libraries automatically // or fallback to "Global" resource var platform = Platform.Instance(); _resource = platform.Type == PlatformType.Unknown ? MonitoredResourceBuilder.GlobalResource : MonitoredResourceBuilder.FromPlatform(platform); foreach (var kvp in _sinkOptions.ResourceLabels) { _resource.Labels[kvp.Key] = kvp.Value; } // use explicit ResourceType if set _resource.Type = sinkOptions.ResourceType ?? _resource.Type; // use explicit project ID or fallback to project ID found in platform environment details above var projectId = _sinkOptions.ProjectId ?? _resource.Labels["project_id"]; _logName = LogFormatter.CreateLogName(projectId, sinkOptions.LogName); _serviceNameAvailable = !String.IsNullOrWhiteSpace(_sinkOptions.ServiceName); _logFormatter = new LogFormatter(projectId, _sinkOptions.UseSourceContextAsLogName, messageTemplateTextFormatter); }
public GoogleCloudLoggingSink(GoogleCloudLoggingSinkOptions sinkOptions, MessageTemplateTextFormatter messageTemplateTextFormatter) { _sinkOptions = sinkOptions; // logging client for google cloud apis // requires extra setup if credentials are passed as raw json text if (sinkOptions.GoogleCredentialJson == null) { _client = LoggingServiceV2Client.Create(); } else { _client = new LoggingServiceV2ClientBuilder { JsonCredentials = sinkOptions.GoogleCredentialJson }.Build(); } // retrieve current environment details (gke/gce/appengine) from google libraries automatically var platform = Platform.Instance(); // resource can be extracted from environment details or fallback to "Global" resource _resource = platform.Type == PlatformType.Unknown ? MonitoredResourceBuilder.GlobalResource : MonitoredResourceBuilder.FromPlatform(platform); foreach (var kvp in _sinkOptions.ResourceLabels) { _resource.Labels[kvp.Key] = kvp.Value; } // use explicit ResourceType if set _resource.Type = sinkOptions.ResourceType ?? _resource.Type; // use explicit project ID or fallback to project ID found in platform environment details above var projectId = _sinkOptions.ProjectId ?? platform.ProjectId ?? _resource.Labels["project_id"]; _logName = LogFormatter.CreateLogName(projectId, sinkOptions.LogName); _logFormatter = new LogFormatter(projectId, _sinkOptions.UseSourceContextAsLogName, messageTemplateTextFormatter); _serviceNameAvailable = !String.IsNullOrWhiteSpace(_sinkOptions.ServiceName); }
public LogFormatter(GoogleCloudLoggingSinkOptions sinkOptions, MessageTemplateTextFormatter messageTemplateTextFormatter) { _sinkOptions = sinkOptions; _messageTemplateTextFormatter = messageTemplateTextFormatter; }