Skip to content

CloudPhoenix/logflake-client-aspnetcore

Repository files navigation

LogFlake Client ASP.NET Core Version

This repository contains the sources for the client-side components of the LogFlake product suite for applications logs and performance collection for ASP.NET applications.

Downloads

NuGet Package Name Version Downloads
LogFlake.Client.AspNetCore NuGet Version NuGet Downloads

Dependencies

This package depends on LogFlake.Client.NetCore. Please refer to the documentation of that package for usage instructions.

Usage

  1. [Optional] If you want to customize some automatic logs from the middleware, add the following section to your secrets.json file:
"LogFlakeMiddlewareSettings": {
    "LogRequest": true,
    "LogResponse": true,
    "LogNotFoundErrors": true
},

All of them are optional, if a boolean property it's missing, the default value is false;

  1. Create a class (name it something like ConfigureLogFlakeMiddlewareOptions) that implements IConfigureOptions<LogFlakeMiddlewareOptions> and configure each property as preferred:
  • GlobalExceptionHandler: This flag let you specify if you want the LogFlakeMiddleware try & catch all the unhandled exceptions in your application. When the flag is set to true, the next method will be surrounded by a try / catch block. In case of any unhandled exception, the OnError will be called.
  • OnError: This function will be called when the middleware encounters a Status Code that is greater or equal to 400, and the Body's response is empty, so you can customize the response depending on the case;
  • GetPerformanceMonitorLabel: For ASP.NET applications, the performance label should be a string representing the Uri with placeholders for variables instead of actual values. Due some limitations of the .NET Standard framework, the Endpoint of the HttpContext cannot be easily accessed inside a Class Library. But you can write your own implementation in order to get a performance label. ℹ️ Suggestion: Use the RoutePattern property of the RouteEndpoint instance taken from httpContext.GetEndpoint().
  • IgnoreLogProcessing: This method will be invocated on each invocation of the middleware to understand if the current request has to be logged or not. It's recommended to use the LogFlakeIgnoreAttribute on the action you want to ignore and check in this method if it's present or not.
  1. Register your class as a Singleton:
services.AddSingleton<IConfigureOptions<LogFlakeMiddlewareOptions>, ConfigureLogFlakeMiddlewareOptions>();
  1. After calling services.AddLogFlake(configuration);, register LogFlakeMiddleware by adding the following line of code:
services.ConfigureLogFlakeMiddlewareOptions(configuration);

Note: The middleware registration will also require a CorrelationId, by default the middleware uses a Guid. You can customize this behavior passing a CorrelationType to the method above, you can also choose a TraceIdentifier or a Custom CorrelationId.

Note: In order to use a Custom CorrelationId you must implement and register (as a AddScoped) ICorrelationService interface.

  1. Register the middleware on your WebApplication
app.UseLogFlakeMiddleware();
  1. If you need to add more parameter to log entries generated by the Middleware (such as data from Claims), you need to implement IParameterService interface and register as a Scoped before the services.ConfigureLogFlakeMiddlewareOptions(configuration); invocation.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages