Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bolorundurowb/logly
A HTTP Request and Response logger for ASP.NET Core
https://github.com/bolorundurowb/logly
Last synced: about 2 months ago
JSON representation
A HTTP Request and Response logger for ASP.NET Core
- Host: GitHub
- URL: https://github.com/bolorundurowb/logly
- Owner: bolorundurowb
- License: mit
- Created: 2018-06-29T03:22:24.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-08-05T11:16:52.000Z (about 4 years ago)
- Last Synced: 2024-05-28T05:47:47.862Z (4 months ago)
- Language: C#
- Homepage:
- Size: 31.3 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# logly
[![CircleCI](https://circleci.com/gh/bolorundurowb/logly.svg?style=svg)](https://circleci.com/gh/bolorundurowb/logly) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE) [![NuGet Badge](https://buildstats.info/nuget/logly)](https://www.nuget.org/packages/logly)
This work is based on that done by _Casey MacPherson_ [here](https://www.codedad.net/2017/08/26/asp-net-core-2-response-logging-2/)
logly is a library written for ASP.NET Core. Its purpose to to make request and response logging more modular and beautiful.
Here is an example of what it looks like:
![logly screenshot](https://res.cloudinary.com/dg2dgzbt4/image/upload/v1530508697/logly_bittgm.png)
## Prerequisite
To prevent the default logging by ASP.NET Core, you would need to make some changes to the default `BuildWebHost` method.This:
```csharp
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup()
.Build();
```becomes this:
```csharp
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureLogging((context, logging) =>
{
logging.ClearProviders();
})
.UseStartup()
.Build();
```## Setup
To add logging, there are two ways, the simple way where you add the following line to the `Configure` method in the `Startup.cs` file.```csharp
app.UseLogly();
```that adds request method, response status code logging and response time logging. If you want to specify more logging options, you can use the `LoggerOptionsBuilder`, as shown below.
```csharp
app.UseLogly(opts => opts
.AddRequestMethod()
.AddStatusCode()
.AddResponseTime()
.AddUrl()
.AddResponseLength());
```