SerilogEcsLogging 1.0.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package SerilogEcsLogging --version 1.0.0
NuGet\Install-Package SerilogEcsLogging -Version 1.0.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="SerilogEcsLogging" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SerilogEcsLogging --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SerilogEcsLogging, 1.0.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 SerilogEcsLogging as a Cake Addin #addin nuget:?package=SerilogEcsLogging&version=1.0.0 // Install SerilogEcsLogging as a Cake Tool #tool nuget:?package=SerilogEcsLogging&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
SerilogEcsLogging
Library adding extensions methods to log ECS-structured events using serilog
Usage
Add SerilogEcsLogging
nuget package to your project:
dotnet add package SerilogEcsLogging
Program.cs:
var builder = WebApplication.CreateBuilder(args);
// ...
builder.Host.UseSerilogEvents(logEcsEvents: true);
// ...
var app = builder.Build();
// ...
app.Run();
Create event class for each event type:
public class ServiceStartupEvent : EventBase
{
private const string ActionName = "ServiceStartup";
public ServiceStartupEvent(bool success = false)
: base(ActionName, success, null /*Captured implicitly by TimedEvent*/, success ? "Service started successfully" : "Service startup failed")
{
}
}
public class DatabaseConnectionEvent : EventBase
{
private const string ActionName = "DatabaseConnection";
public class DatabaseConnectionDetails
{
public string ConnectionString { get; }
public string SchemaVersion { get; }
public DatabaseConnectionDetails(string connectionString, string schemaVersion)
{
ConnectionString = connectionString;
SchemaVersion = schemaVersion;
}
}
public DatabaseConnectionEvent() : base(ActionName, false, null /*Captured implicitly by TimedEvent*/, "Unable to establish connection to database")
{
}
public DatabaseConnectionEvent(string connectionString, string schemaVersion)
: base(ActionName, true, null /*Captured implicitly by TimedEvent*/, "Connected to database", new DatabaseConnectionDetails(connectionString, schemaVersion))
{
}
}
Trace events:
public async Task StartAsync(CancellationToken cancellationToken)
{
using (var startupEvent = logger.BeginTimedEvent(new ServiceStartupEvent(), autoComplete: false))
{
try
{
// Perform app startup tests
// Startup success
startupEvent.Complete(new ServiceStartupEvent(true));
}
catch (Exception e)
{
// Startup failure
startupEvent.Fail(e);
throw;
}
}
using (var ev = logger.BeginTimedEvent(new DatabaseConnectionEvent(), autoComplete: false))
{
try
{
// ...
ev.Complete(new DatabaseConnectionEvent(dataAccess?.ConnectionString, dataAccess?.SchemaVersion));
}
catch (Exception e)
{
ev.Fail(e);
throw;
}
}
Traced ECS event:
{
"@timestamp": "2023-02-10T08:55:22.6289711-06:00",
"log.level": "Information",
"message": "Connected to database",
"tags": ["testApp"],
"ecs": {
"version": "1.5.0"
},
"event": {
"kind": "event",
"action": "DatabaseConnection",
"outcome": "success",
"severity": 4,
"timezone": "Central Standard Time",
"created": "2023-02-10T08:55:22.6289711-06:00",
"start": "2023-02-10T08:55:22-06:00"
},
"host": {
"name": "test-ec2"
},
"log": {
"logger": "testApp.Startup.Startup",
"original": null,
"origin": {
"file": {
"name": "Startup.cs",
"line": 37
},
"function": "StartAsync"
}
},
"process": {
"thread": {
"id": 4
},
"pid": 348,
"name": "testApp",
"executable": "testApp"
},
"server": {
"user": {
"name": "test"
}
},
"service": {
"name": "testApp",
"version": "1.0.0.0"
},
"Data": {
"connection_string": "Server=localhost;Port=3306;Database=test_db;User ID=test_user",
"schema_version": "1.0",
"$type": "DatabaseConnectionDetails"
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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 was computed. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- Elastic.CommonSchema.Serilog (>= 1.5.3)
- Microsoft.Extensions.Hosting.Abstractions (>= 6.0.0)
- Serilog.Enrichers.AssemblyName (>= 1.0.9)
- Serilog.Enrichers.CorrelationId (>= 3.0.1)
- Serilog.Enrichers.Environment (>= 2.2.0)
- Serilog.Enrichers.Process (>= 2.0.2)
- Serilog.Enrichers.Thread (>= 3.1.0)
- Serilog.Extensions.Hosting (>= 5.0.1)
- Serilog.Settings.Configuration (>= 3.4.0)
- Serilog.Sinks.Async (>= 1.5.0)
- Serilog.Sinks.Console (>= 4.1.0)
- Serilog.Sinks.File (>= 5.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.