elando.ELK.TraceLogging 6.0.0

Suggested Alternatives

elando.ELK.TraceLogging 1.6.0

Additional Details

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
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="elando.ELK.TraceLogging" Version="6.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add elando.ELK.TraceLogging --version 6.0.0
#r "nuget: elando.ELK.TraceLogging, 6.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 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 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.

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