elando.ELK.TraceLogging
6.0.0
Support 1.6.0. or later as multi target net version 6,7,8
dotnet add package elando.ELK.TraceLogging --version 6.0.0
NuGet\Install-Package elando.ELK.TraceLogging -Version 6.0.0
<PackageReference Include="elando.ELK.TraceLogging" Version="6.0.0" />
paket add elando.ELK.TraceLogging --version 6.0.0
#r "nuget: elando.ELK.TraceLogging, 6.0.0"
// Install elando.ELK.TraceLogging as a Cake Addin
#addin nuget:?package=elando.ELK.TraceLogging&version=6.0.0
// Install elando.ELK.TraceLogging as a Cake Tool
#tool nuget:?package=elando.ELK.TraceLogging&version=6.0.0
Package for Request Tracing with Serilog
This package provides an easy configuration to trace HTTP requests using Serilog. Please follow the steps below to set it up.
Configuration Steps
1. Configure Serilog for Elasticsearch
In order to use this package, you need to configure Serilog to work with Elasticsearch. You can do this by calling AddElasticLogging()
in SerilogConfigurationExtensions.cs
. Additionally, make sure to provide the following configuration parameters:
elasticUri
indexPrefix
minLoggingLevel
OR
UseDirect Host Configuration about Serilog (with Elastic). You can do this by calling builder.Host.AddLogger()
in HostExtension.cs
. Additionally, make sure to provide the following configuration parameters:
builder.Configuration
LogEventLevel logLevel = LogEventLevel.Information
2. Add configuration property for header name into appsettings.json
{
"TraceIdKey": "Your-Custom_Key-Name",
"ElasticUri": "your.elastic.uri/",
"LoggerPrefix": "Your-Custom_Prefix",
"GlobalLogingFilter": "Your-Custom_Loging-Filter" // Optional
}
3. Add HttpContextAccessor via Dependency Injection
Each middleware in this package requires access to the HTTP context. To provide access, add the HttpContextAccessor
to your DI container using:
builder.Services.AddHttpContextAccessor();
4. Configure HTTP Logging
Configure HTTP request/response logging using the following code:
builder.Services.AddHttpLogging(logging =>
{
logging.RequestHeaders.Add(builder.Configuration.GetHeaderName());
});
5. Use Trace Identifier Middleware
Not needed for application inside the kube8. Add the TraceIdentifierMiddleware as the first middleware in your application to include a new trace header with a unique GUID:
app.UseMiddleware<HttpTraceMiddleware>();
6. Use HTTP Logging Middleware
Use UseHttpLogging() as the second middleware in your application to log the HTTP requests and responses:
app.UseHttpLogging();
7. Additional Configuration
Not needed for application inside the kube8. If you need to trace:
7.1. gRPC Calls
Add the TraceIdentifierInterceptor to your services:
services.AddSingleton<HttpTraceInterceptor>();
Configure each gRPC client with the TraceIdentifierInterceptor:
services.AddGrpcClient<gRPCClient>(options => ...)
.AddInterceptor<HttpTraceInterceptor>();
7.2. HTTP Requests
Note that HTTP requests are not implemented yet and require further development.
8. Logging Extensions
Use LoggerTraceExtensions based on 'Microsoft.Extensions.Logging.ILogger'.
8.1 Example: How to use LoggerTraceExtensions.
var traceId = this.HttpContext.GetTraceId();
_logger.LogModelWithDepthOne(request, traceId);
The traceId argument enables tracing of the log in an application & across microservice architecture.
8.2 Example: Redact sensitive data - object
var traceId = this.HttpContext.GetTraceId();
_logger.LogModelWithDepthOne(model, traceId, nameof(model.Phone));
8.3 Example: Redact sensitive data - collection
var traceId = this.HttpContext.GetTraceId();
// New code
IEnumerable<TypeModel> copy = model.DeepCopy();
copy.RedactSensitiveData(nameof(TypeModel.Address), nameof(TypeModel.Phone));
_logger.LogModelWithDepthOne(copy, traceId);
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. |
-
net6.0
- Google.Protobuf (>= 3.24.3)
- Grpc.Core.Api (>= 2.57.0)
- Microsoft.AspNetCore.Http.Abstractions (>= 2.1.1)
- Microsoft.Extensions.Configuration.Abstractions (>= 7.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 7.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 7.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 7.0.1)
- Newtonsoft.Json (>= 13.0.3)
- Serilog (>= 3.0.1)
- Serilog.AspNetCore (>= 7.0.0)
- Serilog.Enrichers.Environment (>= 2.2.0)
- Serilog.Enrichers.Process (>= 2.0.2)
- Serilog.Enrichers.Thread (>= 3.1.0)
- Serilog.Extensions.Logging (>= 7.0.0)
- Serilog.Settings.Configuration (>= 7.0.1)
- Serilog.Sinks.Console (>= 4.1.0)
- Serilog.Sinks.Elasticsearch (>= 9.0.3)
- System.IdentityModel.Tokens.Jwt (>= 6.19.0)
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 | |
---|---|---|---|
6.0.0 | 278 | 12/11/2023 | |
1.6.0 | 33 | 6/24/2024 | |
1.5.2 | 753 | 11/29/2023 | |
1.5.1 | 110 | 11/28/2023 | |
1.5.0 | 88 | 11/27/2023 | |
1.4.4 | 720 | 9/28/2023 | |
1.4.3 | 307 | 9/26/2023 | |
1.4.2 | 87 | 9/26/2023 | |
1.4.1 | 108 | 9/26/2023 | |
1.4.0 | 117 | 9/26/2023 | |
1.3.5 | 141 | 9/25/2023 | |
1.3.4 | 106 | 9/21/2023 | |
1.3.3 | 81 | 9/20/2023 | |
1.3.2 | 110 | 9/20/2023 | |
1.3.1 | 106 | 9/20/2023 | |
1.3.0 | 112 | 9/20/2023 | |
1.2.0 | 98 | 9/19/2023 | |
1.1.1 | 222 | 9/8/2023 | |
1.1.0 | 101 | 9/8/2023 | |
1.0.0 | 123 | 9/8/2023 |