Serilog.Sinks.Aliyun-SLS 0.2.0

dotnet add package Serilog.Sinks.Aliyun-SLS --version 0.2.0
NuGet\Install-Package Serilog.Sinks.Aliyun-SLS -Version 0.2.0
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.Aliyun-SLS" Version="0.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Serilog.Sinks.Aliyun-SLS --version 0.2.0
#r "nuget: Serilog.Sinks.Aliyun-SLS, 0.2.0"
#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.
// Install Serilog.Sinks.Aliyun-SLS as a Cake Addin
#addin nuget:?package=Serilog.Sinks.Aliyun-SLS&version=0.2.0

// Install Serilog.Sinks.Aliyun-SLS as a Cake Tool
#tool nuget:?package=Serilog.Sinks.Aliyun-SLS&version=0.2.0

Serilog.Sinks.Aliyun release NuGet

A Serilog sink that writes events to the Aliyun SLS.

Getting started

Install Serilog.Sinks.Aliyun-SLS into your .NET project:

> dotnet add package Serilog.Sinks.Aliyun-SLS

Point the logger to Aliyun:

Log.Logger = new LoggerConfiguration()
    .WriteTo.Aliyun("<accessKeyId>", "<accessKeySecret>", "<endpoint>", "<project>", "<logStore>")
    .CreateLogger();

And use the Serilog logging methods to associate named properties with log events:

Log.Error("Failed to log on user {ContactId}", contactId);

Then query log event properties like ContactId from the browser:

When the application shuts down, ensure any buffered events are propertly flushed to Aliyun by disposing the logger or calling Log.CloseAndFlush():

Log.CloseAndFlush();

JSON appsettings.json configuration

To use the Aliyun sink with Microsoft.Extensions.Configuration, for example with ASP.NET Core or .NET Core, use the Serilog.Settings.Configuration package. First install that package if you have not already done so:

dotnet add package Serilog.Settings.Configuration

Instead of configuring the Aliyun sink directly in code, call ReadFrom.Configuration():

var configuration = new ConfigurationBuilder()
    .AddJsonFile("appsettings.json")
    .Build();

var logger = new LoggerConfiguration()
    .ReadFrom.Configuration(configuration)
    .CreateLogger();

In your appsettings.json file, under the Serilog node, :

{
  "Serilog": {
    "WriteTo": [
      {
        "Name": "Aliyun",
        "Args": {
          "endpoint": "",
          "project": "",
          "logStore": "",
          "accessKeyId": "",
          "accessKeySecret": ""
        }
      }
    ]
  }
}

Dynamic log level control

The Aliyun sink can dynamically adjust the logging level up or down based on the level associated with an API key in Aliyun. To use this feature, create a LoggingLevelSwitch to control the MinimumLevel, and pass this in the controlLevelSwitch parameter of WriteTo.Aliyun():

var levelSwitch = new LoggingLevelSwitch();

Log.Logger = new LoggerConfiguration()
    .MinimumLevel.ControlledBy(levelSwitch)
    .WriteTo.Aliyun(... , controlLevelSwitch: levelSwitch)
    .CreateLogger();

The equivalent configuration in JSON is:

{
  "Serilog": {
    "LevelSwitches": { "$controlSwitch": "Information" },
    "MinimumLevel": { "ControlledBy": "$controlSwitch" },
    "WriteTo": [
      {
        "Name": "Aliyun",
        "Args": {}
      }
    ]
  }
}

Troubleshooting

Client-side issues

If there's no information in the ingestion log, the application was probably unable to reach the server because of network configuration or connectivity issues. These are reported to the application through Serilog's SelfLog.

Add the following line after the logger is configured to print any error information to the console:

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

If the console is not available, you can pass a delegate into SelfLog.Enable() that will be called with each error message:

Serilog.Debugging.SelfLog.Enable(message => {
    // Do something with `message`
});
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.2.0 561 8/18/2023
0.1.0 162 8/15/2023