/// <summary> /// Activates logging to AWS CloudWatch /// </summary> /// <remarks>This overload is intended to be used via AppSettings integration.</remarks> /// <param name="loggerConfiguration">The LoggerSinkConfiguration to register this sink with.</param> /// <param name="logGroupName">The log group name to be used in AWS CloudWatch.</param> /// <param name="regionName">The system name of the region to which to write.</param> /// <param name="logStreamNamePrefix">The log stream name prefix. Will use default log stream name if leave empty.</param> /// <param name="formatter">A formatter to format Serilog's LogEvent.</param> /// <param name="minimumLogEventLevel">The minimum log event level required in order to write an event to the sink.</param> /// <param name="batchSizeLimit">The batch size to be used when uploading logs to AWS CloudWatch.</param> /// <param name="period">The period to be used when a batch upload should be triggered.</param> /// <returns></returns> /// <exception cref="ArgumentNullException"><paramref name="logGroupName"/> is <see langword="null"/>.</exception> public static LoggerConfiguration AmazonCloudWatch( this LoggerSinkConfiguration loggerConfiguration, string logGroupName, ITextFormatter formatter, string regionName = null, string logStreamNamePrefix = null, LogEventLevel minimumLogEventLevel = CloudWatchSinkOptions.DefaultMinimumLogEventLevel, int batchSizeLimit = CloudWatchSinkOptions.DefaultBatchSizeLimit, TimeSpan?period = null, bool createLogGroup = CloudWatchSinkOptions.DefaultCreateLogGroup) { if (logGroupName == null) { throw new ArgumentNullException(nameof(logGroupName)); } var options = new CloudWatchSinkOptions { LogGroupName = logGroupName, MinimumLogEventLevel = minimumLogEventLevel, BatchSizeLimit = batchSizeLimit, Period = period ?? CloudWatchSinkOptions.DefaultPeriod, TextFormatter = formatter, CreateLogGroup = createLogGroup }; if (!String.IsNullOrWhiteSpace(logStreamNamePrefix)) { options.LogStreamNameProvider = new ConstantLogStreamNameProvider(logStreamNamePrefix); } var client = CreateClient(regionName); return(loggerConfiguration.AmazonCloudWatch(options, client)); }
/// <summary> /// Activates logging to AWS CloudWatch /// </summary> /// <remarks>This overload is intended to be used via AppSettings integration.</remarks> /// <param name="loggerConfiguration">The LoggerSinkConfiguration to register this sink with.</param> /// <param name="logGroupName">The log group name to be used in AWS CloudWatch.</param> /// <param name="accessKey">The access key to use to access AWS CloudWatch.</param> /// <param name="secretAccessKey">The secret access key to use to access AWS CloudWatch.</param> /// <param name="regionName">The system name of the region to which to write.</param> /// <param name="logStreamNamePrefix">The log stream name prefix. Will use default log stream name if leave empty.</param> /// <param name="rendererType">The renderer to be used to format the message.</param> /// <param name="minimumLogEventLevel">The minimum log event level required in order to write an event to the sink.</param> /// <param name="batchSizeLimit">The batch size to be used when uploading logs to AWS CloudWatch.</param> /// <param name="period">The period to be used when a batch upload should be triggered.</param> /// <returns></returns> /// <exception cref="ArgumentNullException"><paramref name="logGroupName"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentNullException"><paramref name="accessKey"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentNullException"><paramref name="secretAccessKey"/> is <see langword="null"/>.</exception> public static LoggerConfiguration AmazonCloudWatch( this LoggerSinkConfiguration loggerConfiguration, string logGroupName, string accessKey, string secretAccessKey, string regionName = null, string logStreamNamePrefix = null, RendererType rendererType = RendererType.DefaultRenderer, LogEventLevel minimumLogEventLevel = CloudWatchSinkOptions.DefaultMinimumLogEventLevel, int batchSizeLimit = CloudWatchSinkOptions.DefaultBatchSizeLimit, TimeSpan?period = null) { ILogEventRenderer logEventRenderer = new DefaultLogEventRenderer(); if (rendererType == RendererType.JsonRenderer) { logEventRenderer = new JsonLogEventRenderer(); } return(loggerConfiguration.AmazonCloudWatch(logGroupName, accessKey, secretAccessKey, regionName, logStreamNamePrefix, logEventRenderer, minimumLogEventLevel, batchSizeLimit, period)); }
/// <summary> /// Activates logging to AWS CloudWatch /// </summary> /// <remarks>This overload is intended to be used via AppSettings integration.</remarks> /// <param name="loggerConfiguration">The LoggerSinkConfiguration to register this sink with.</param> /// <param name="logGroupName">The log group name to be used in AWS CloudWatch.</param> /// <param name="logStreamNameProvider">The log stream name provider.</param> /// <param name="regionName">The system name of the region to which to write.</param> /// <param name="logEventRenderer">A renderer to render Serilog's LogEvent.</param> /// <param name="minimumLogEventLevel">The minimum log event level required in order to write an event to the sink.</param> /// <param name="batchSizeLimit">The batch size to be used when uploading logs to AWS CloudWatch.</param> /// <param name="period">The period to be used when a batch upload should be triggered.</param> /// <returns></returns> /// <exception cref="ArgumentNullException"><paramref name="logGroupName"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentNullException"><paramref name="logStreamNameProvider"/> is <see langword="null"/>.</exception> public static LoggerConfiguration AmazonCloudWatch( this LoggerSinkConfiguration loggerConfiguration, string logGroupName, ILogStreamNameProvider logStreamNameProvider, string regionName = null, ILogEventRenderer logEventRenderer = null, LogEventLevel minimumLogEventLevel = CloudWatchSinkOptions.DefaultMinimumLogEventLevel, int batchSizeLimit = CloudWatchSinkOptions.DefaultBatchSizeLimit, TimeSpan?period = null, bool createLogGroup = CloudWatchSinkOptions.DefaultCreateLogGroup) { if (logGroupName == null) { throw new ArgumentNullException(nameof(logGroupName)); } if (logStreamNameProvider == null) { throw new ArgumentNullException(nameof(logStreamNameProvider)); } var options = new CloudWatchSinkOptions { LogGroupName = logGroupName, MinimumLogEventLevel = minimumLogEventLevel, BatchSizeLimit = batchSizeLimit, Period = period ?? CloudWatchSinkOptions.DefaultPeriod, LogStreamNameProvider = logStreamNameProvider, LogEventRenderer = logEventRenderer, CreateLogGroup = createLogGroup }; var client = CreateClient(regionName); return(loggerConfiguration.AmazonCloudWatch(options, client)); }
/// <summary> /// Activates logging to AWS CloudWatch /// </summary> /// <remarks>This overload is intended to be used via AppSettings integration.</remarks> /// <param name="loggerConfiguration">The LoggerSinkConfiguration to register this sink with.</param> /// <param name="logGroupName">The log group name to be used in AWS CloudWatch.</param> /// <param name="accessKey">The access key to use to access AWS CloudWatch.</param> /// <param name="secretAccessKey">The secret access key to use to access AWS CloudWatch.</param> /// <param name="regionName">The system name of the region to which to write.</param> /// <param name="logStreamNamePrefix">The log stream name prefix. Will use default log stream name if leave empty.</param> /// <param name="logEventRenderer">A renderer to render Serilog's LogEvent.</param> /// <param name="minimumLogEventLevel">The minimum log event level required in order to write an event to the sink.</param> /// <param name="batchSizeLimit">The batch size to be used when uploading logs to AWS CloudWatch.</param> /// <param name="period">The period to be used when a batch upload should be triggered.</param> /// <returns></returns> /// <exception cref="ArgumentNullException"><paramref name="logGroupName"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentNullException"><paramref name="accessKey"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentNullException"><paramref name="secretAccessKey"/> is <see langword="null"/>.</exception> public static LoggerConfiguration AmazonCloudWatch( this LoggerSinkConfiguration loggerConfiguration, string logGroupName, string accessKey, string secretAccessKey, string regionName = null, string logStreamNamePrefix = null, ILogEventRenderer logEventRenderer = null, LogEventLevel minimumLogEventLevel = CloudWatchSinkOptions.DefaultMinimumLogEventLevel, int batchSizeLimit = CloudWatchSinkOptions.DefaultBatchSizeLimit, TimeSpan?period = null, bool createLogGroup = CloudWatchSinkOptions.DefaultCreateLogGroup) { if (logGroupName == null) { throw new ArgumentNullException(nameof(logGroupName)); } if (accessKey == null) { throw new ArgumentNullException(nameof(accessKey)); } if (secretAccessKey == null) { throw new ArgumentNullException(nameof(secretAccessKey)); } var options = new CloudWatchSinkOptions { LogGroupName = logGroupName, MinimumLogEventLevel = minimumLogEventLevel, BatchSizeLimit = batchSizeLimit, Period = period ?? CloudWatchSinkOptions.DefaultPeriod, LogEventRenderer = logEventRenderer, CreateLogGroup = createLogGroup }; if (!String.IsNullOrWhiteSpace(logStreamNamePrefix)) { options.LogStreamNameProvider = new ConstantLogStreamNameProvider(logStreamNamePrefix); } var credentials = new BasicAWSCredentials(accessKey, secretAccessKey); IAmazonCloudWatchLogs client; if (regionName != null) { var region = RegionEndpoint.GetBySystemName(regionName); client = new AmazonCloudWatchLogsClient(credentials, region); } else { client = new AmazonCloudWatchLogsClient(credentials); } return(loggerConfiguration.AmazonCloudWatch(options, client)); }