![]() |
VOOZH | about |
dotnet add package Serilog.Sinks.Aliyun-SLS --version 1.2.1
NuGet\Install-Package Serilog.Sinks.Aliyun-SLS -Version 1.2.1
<PackageReference Include="Serilog.Sinks.Aliyun-SLS" Version="1.2.1" />
<PackageVersion Include="Serilog.Sinks.Aliyun-SLS" Version="1.2.1" />Directory.Packages.props
<PackageReference Include="Serilog.Sinks.Aliyun-SLS" />Project file
paket add Serilog.Sinks.Aliyun-SLS --version 1.2.1
#r "nuget: Serilog.Sinks.Aliyun-SLS, 1.2.1"
#:package Serilog.Sinks.Aliyun-SLS@1.2.1
#addin nuget:?package=Serilog.Sinks.Aliyun-SLS&version=1.2.1Install as a Cake Addin
#tool nuget:?package=Serilog.Sinks.Aliyun-SLS&version=1.2.1Install as a Cake Tool
A Serilog sink that writes events to the Aliyun SLS.
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();
appsettings.json configurationTo 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": ""
}
}
]
}
}
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": {}
}
]
}
}
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 | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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 is compatible. 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. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.