VOOZH about

URL: https://www.nuget.org/packages/Serilog.Sinks.AwsCloudWatch/

⇱ NuGet Gallery | Serilog.Sinks.AwsCloudWatch 4.4.42




👁 Image
Serilog.Sinks.AwsCloudWatch 4.4.42

dotnet add package Serilog.Sinks.AwsCloudWatch --version 4.4.42
 
 
NuGet\Install-Package Serilog.Sinks.AwsCloudWatch -Version 4.4.42
 
 
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Serilog.Sinks.AwsCloudWatch" Version="4.4.42" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Serilog.Sinks.AwsCloudWatch" Version="4.4.42" />
 
Directory.Packages.props
<PackageReference Include="Serilog.Sinks.AwsCloudWatch" />
 
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Serilog.Sinks.AwsCloudWatch --version 4.4.42
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Serilog.Sinks.AwsCloudWatch, 4.4.42"
 
 
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Serilog.Sinks.AwsCloudWatch@4.4.42
 
 
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Serilog.Sinks.AwsCloudWatch&version=4.4.42
 
Install as a Cake Addin
#tool nuget:?package=Serilog.Sinks.AwsCloudWatch&version=4.4.42
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Serilog Sink for AWS CloudWatch

This Serilog Sink allows to log to AWS CloudWatch.

Version and build status

👁 NuGet version

Usage

There are two important aspects for configuring this library. The first is providing the configuration options necessary via the ICloudWatchSinkOptions implementation. And the second is configuring the AWS Credentials. Both of these are required to log to CloudWatch.

Installation

dotnet add package Serilog.Sinks.AwsCloudWatch

CloudWatchSinkOptions

This library provides an extension method which takes in only a ICloudWatchSinkOptions instance and the IAmazonCloudWatchLogs instance.

Configuration via Code First

The preferred approach for configuration is to construct the necessary objects via code and pass them directly to the library extension method.

 // name of the log group
 var logGroupName = "myLogGroup/" + env.EnvironmentName;

 // customer formatter
 var formatter = new MyCustomTextFormatter();

 // options for the sink defaults in https://github.com/Cimpress-MCP/serilog-sinks-awscloudwatch/blob/master/src/Serilog.Sinks.AwsCloudWatch/CloudWatchSinkOptions.cs
 var options = new CloudWatchSinkOptions
 {
 // the name of the CloudWatch Log group for logging
 LogGroupName = logGroupName,

 // the main formatter of the log event
 TextFormatter = formatter,
 
 // other defaults defaults
 MinimumLogEventLevel = LogEventLevel.Information,
 BatchSizeLimit = 100,
 QueueSizeLimit = 10000,
 Period = TimeSpan.FromSeconds(10),
 CreateLogGroup = true,
 LogStreamNameProvider = new DefaultLogStreamProvider(),
 RetryAttempts = 5
 };

 // setup AWS CloudWatch client
 var client = new AmazonCloudWatchLogsClient(myAwsRegion);

 // Attach the sink to the logger configuration
 Log.Logger = new LoggerConfiguration()
 .WriteTo.AmazonCloudWatch(options, client)
 .CreateLogger();
Configuration via Fluent Code First

Call the extension method passing the configuration values that you wish to make use of.

 // setup AWS CloudWatch client
 var client = myAppConfigRoot.GetAWSOptions().CreateServiceClient<IAmazonCloudWatchLogs>();

 // Attach the sink to the logger configuration
 Log.Logger = new LoggerConfiguration()
 .WriteTo.AmazonCloudWatch(
		"myLogGroup/" + env.EnvironmentName, 
		batchSizeLimit = 100,
		queueSizeLimit = 10000,
		batchUploadPeriodInSeconds = 15,
		createLogGroup = true,
		maxRetryAttempts = 3
		cloudWatchClient = client)
 .CreateLogger();
Configuration via config file

While not recommended, it is still possible to config the library via a configuration file. There are two libraries which provide these capabilities.

  • Serilog.Settings.AppSettings Configuration is done by App.config or Web.config file. Create a concrete implementation of the ICloudWatchSinkOptions interface, and specify the necessary configuration values. Then in the configuration file, specify the following:
 
 <add key="serilog:write-to:AmazonCloudWatch.options" value="{namespace}.CloudWatchSinkOptions, {assembly}, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
  • Serilog.Settings.Configuration Configuration is done by an appsettings.json file (or optional specific override. Create a concrete implementation of the ICloudWatchSinkOptions interface, and specify the necessary configuration values. Then in the configuration file, specify the following:
 // {Assembly} name is `typeof(YourOptionsClass).AssemblyQualifiedName` and {Namespace} is the class namespace.
 {
 "Args": {
 "options": "{namespace}.CloudWatchSinkOptions, {assembly}"
 }
 }

Alternatively you may configure the library without creating a concrete instance of the ICloudWatchSinkOptions interface however this will cause the AWS Service client to follow the credential rules in the official AWS SDK documentation. You may configure any of the passed values in the Extension method.

 {
 "Serilog": {
 "Using": [ "Serilog.Sinks.AwsCloudWatch" ],
 "MinimumLevel": "Verbose",
 "WriteTo": [ 
 {
 "Name": "AmazonCloudWatch",
 "Args": {
 "logGroup": "your-app",
 "logStreamPrefix": "environment/component",
 "restrictedToMinimumLevel": "Verbose"
 }
 }
 ]
 }
 }

or using XML:

 <add key="serilog:using:AwsCloudWatch" value="Serilog.Sinks.AwsCloudWatch" />
 <add key="serilog:write-to:AmazonCloudWatch.logGroup" value="your-app" />
 <add key="serilog:write-to:AmazonCloudWatch.logStreamPrefix" value="environment/component" />
 <add key="serilog:write-to:AmazonCloudWatch.restrictedToMinimumLevel" value="Verbose" />

Configuring Credentials

AmazonCloudWatchLogsClient from the AWS SDK requires AWS credentials. To correctly associate credentials with the library, please refer to The Official AWS Recommendation on C# for credentials management. To reiterate here:

  • Preferred ⇒ Use IAM Profile set on your instance, machine, lambda function.
  • Create a credentials profile with your AWS credentials.
  • Use Environment Variables
  • Manually construct the credentials via:
 var options = new CredentialProfileOptions { AccessKey = "access_key", SecretKey = "secret_key" };
 var profile = new Amazon.Runtime.CredentialManagement.CredentialProfile("basic_profile", options);
 profile.Region = GetBySystemName("eu-west-1"); // OR RegionEndpoint.EUWest1
 var netSDKFile = new NetSDKCredentialsFile();
 netSDKFile.RegisterProfile(profile);

Troubleshooting

  • Cannot find region in config or Cannot find credentials in config AWS configuration is not complete. Refer to the Configuring Credentials section to complete the configuration.

  • Errors related to the setup of the Sink (for example, invalid AWS credentials), or problems during sending the data are logged to Serilog's SelfLog. Short version, enable it with something like the following command:

 Serilog.Debugging.SelfLog.Enable(Console.Error);

Contribution

We value your input as part of direct feedback to us, by filing issues, or preferably by directly contributing improvements:

  1. Fork this repository
  2. Create a branch
  3. Contribute
  4. Pull request
Product Versions Compatible and additional computed target framework versions.
.NET net5.0 net5.0 was computed.  net5.0-windows net5.0-windows was computed.  net6.0 net6.0 is compatible.  net6.0-android net6.0-android was computed.  net6.0-ios net6.0-ios was computed.  net6.0-maccatalyst net6.0-maccatalyst was computed.  net6.0-macos net6.0-macos was computed.  net6.0-tvos net6.0-tvos was computed.  net6.0-windows net6.0-windows was computed.  net7.0 net7.0 was computed.  net7.0-android net7.0-android was computed.  net7.0-ios net7.0-ios was computed.  net7.0-maccatalyst net7.0-maccatalyst was computed.  net7.0-macos net7.0-macos was computed.  net7.0-tvos net7.0-tvos was computed.  net7.0-windows net7.0-windows was computed.  net8.0 net8.0 is compatible.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 was computed.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 was computed.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows net10.0-windows was computed. 
.NET Core netcoreapp2.0 netcoreapp2.0 was computed.  netcoreapp2.1 netcoreapp2.1 was computed.  netcoreapp2.2 netcoreapp2.2 was computed.  netcoreapp3.0 netcoreapp3.0 was computed.  netcoreapp3.1 netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 netstandard2.0 is compatible.  netstandard2.1 netstandard2.1 was computed. 
.NET Framework net461 net461 was computed.  net462 net462 was computed.  net463 net463 was computed.  net47 net47 was computed.  net471 net471 was computed.  net472 net472 was computed.  net48 net48 was computed.  net481 net481 was computed. 
MonoAndroid monoandroid monoandroid was computed. 
MonoMac monomac monomac was computed. 
MonoTouch monotouch monotouch was computed. 
Tizen tizen40 tizen40 was computed.  tizen60 tizen60 was computed. 
Xamarin.iOS xamarinios xamarinios was computed. 
Xamarin.Mac xamarinmac xamarinmac was computed. 
Xamarin.TVOS xamarintvos xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (20)

Showing the top 5 NuGet packages that depend on Serilog.Sinks.AwsCloudWatch:

Package Downloads
Aj.Platform.Core

Biblioteca de Uso Geral para integrações com as API OmsAj

Serilog.Sinks.AwsCloudWatch.Extensions

Configuration extension for the AwsCloudWatch Serilog sink

Informatique.Base.Core

Base classed used in Project in Core

CBORD.Omni.Domain

Package Description

ITMakers.InfraestructureBase

Shared libraries for infrastructure in IT Makers' apps

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.4.42 2,458,582 5/7/2025
4.3.37 3,404,538 7/23/2024
4.2.34 85,425 7/19/2024
4.2.29 472,370 5/20/2024
4.2.25 206,153 4/11/2024
4.2.24 52,956 4/2/2024
4.2.19 83,876 3/18/2024
4.2.17 27,422 3/15/2024
4.1.15 12,614 3/15/2024
4.1.14 17,307 3/15/2024
4.0.182 1,594,761 9/20/2023
4.0.180 11,251 9/19/2023
4.0.178 1,118,663 7/12/2023
4.0.171 8,120,387 4/22/2021
4.0.168 1,010,318 2/11/2021
4.0.167 56,088 2/11/2021
4.0.161 804,337 9/9/2020
4.0.159 1,256,207 2/28/2020
4.0.155 870,179 5/22/2019
4.0.149 247,711 2/22/2019
Loading failed