{"id":26190427,"url":"https://github.com/yavorfingarov/simplerequestlogger","last_synced_at":"2025-10-15T02:20:08.101Z","repository":{"id":36988088,"uuid":"442577468","full_name":"yavorfingarov/SimpleRequestLogger","owner":"yavorfingarov","description":"A simple and customizable ASP.NET Core middleware for structured logging of requests.","archived":false,"fork":false,"pushed_at":"2023-08-09T00:39:03.000Z","size":102,"stargazers_count":1,"open_issues_count":5,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-08T21:45:43.939Z","etag":null,"topics":["aspnetcore","logging","middleware"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yavorfingarov.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-12-28T20:35:31.000Z","updated_at":"2024-01-12T10:24:02.000Z","dependencies_parsed_at":"2023-01-17T11:47:33.847Z","dependency_job_id":null,"html_url":"https://github.com/yavorfingarov/SimpleRequestLogger","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yavorfingarov%2FSimpleRequestLogger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yavorfingarov%2FSimpleRequestLogger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yavorfingarov%2FSimpleRequestLogger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yavorfingarov%2FSimpleRequestLogger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yavorfingarov","download_url":"https://codeload.github.com/yavorfingarov/SimpleRequestLogger/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243136194,"owners_count":20241989,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aspnetcore","logging","middleware"],"created_at":"2025-03-12T00:53:56.452Z","updated_at":"2025-10-15T02:20:07.999Z","avatar_url":"https://github.com/yavorfingarov.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SimpleRequestLogger\n\n[![nuget](https://img.shields.io/nuget/v/SimpleRequestLogger)](https://www.nuget.org/packages/SimpleRequestLogger)\n[![downloads](https://img.shields.io/nuget/dt/SimpleRequestLogger?color=blue)](https://www.nuget.org/stats/packages/SimpleRequestLogger?groupby=Version)\n[![cd](https://img.shields.io/github/actions/workflow/status/yavorfingarov/SimpleRequestLogger/cd.yml?branch=master\u0026label=cd)](https://github.com/yavorfingarov/SimpleRequestLogger/actions/workflows/cd.yml?query=branch%3Amaster)\n[![codeql](https://img.shields.io/github/actions/workflow/status/yavorfingarov/SimpleRequestLogger/codeql.yml?branch=master\u0026label=codeql)](https://github.com/yavorfingarov/SimpleRequestLogger/actions/workflows/codeql.yml?query=branch%3Amaster)\n[![loc](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/yavorfingarov/ee725e01afca4342ff8ea785553d05d2/raw/lines-of-code.json)](https://github.com/yavorfingarov/SimpleRequestLogger/actions/workflows/cd.yml?query=branch%3Amaster)\n[![test coverage](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/yavorfingarov/ee725e01afca4342ff8ea785553d05d2/raw/test-coverage.json)](https://github.com/yavorfingarov/SimpleRequestLogger/actions/workflows/cd.yml?query=branch%3Amaster)\n[![mutation score](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/yavorfingarov/ee725e01afca4342ff8ea785553d05d2/raw/mutation-score.json)](https://github.com/yavorfingarov/SimpleRequestLogger/actions/workflows/cd.yml?query=branch%3Amaster)\n\nSimpleRequestLogger is a small and customizable ASP.NET Core middleware for structured logging\nof requests using `Microsoft.Extensions.Logging`. The built-in request logging is a bit noisy\nand emits multiple events per request. With SimpleRequestLogger you can fit all the information\nyou need in a single log entry:\n\n```\n// Plaintext\n21:51:46.5705 [INF] GET / responded 200 in 31 ms.\n\n// JSON\n{\n    \"Time\": \"21:51:46.5705\",\n    \"Level\": \"INF\",\n    \"Message\": \"GET / responded 200 in 31 ms.\",\n    \"Properties\": {\n        \"Method\": \"GET\",\n        \"Path\": \"/\",\n        \"QueryString\": \"\",\n        \"StatusCode\": 200,\n        \"ElapsedMs\": 31\n    }\n}\n```\n\n## Getting started\n\nInstall the [NuGet package](https://www.nuget.org/packages/SimpleRequestLogger) and\nadd the middleware at the beginning of your request pipeline:\n\n```csharp\napp.UseRequestLogging();\n```\n\n## Configuration\n\nBy default, SimpleRequestLogger logs all requests at information log level with message\ntemplate `\"{Method} {Path}{QueryString} responded {StatusCode} in {ElapsedMs} ms.\"`.\n\nIt is possible to customize the message template, to change the log level based on\nstatus code and to disable logging for specific paths. SimpleRequestLogger uses\n`Microsoft.Extensions.Configuration` and would by default expect a section `RequestLogging`.\n\n```json\n\"RequestLogging\": {\n    \"MessageTemplate\": \"{Scheme} {Method} {Path} =\u003e {StatusCode}\",\n    \"IgnorePaths\": [ \"/health\", \"/static/*\" ]\n}\n```\n\nIt is also possible to pass a custom configuration section:\n\n```csharp\napp.UseRequestLogging(\"YourCustomSection:CustomSubsectionRequestLogging\");\n```\n\nTo change the log level based on status code, you should pass a delegate to the middleware:\n\n```csharp\napp.UseRequestLogging(statusCode =\u003e (statusCode \u003c 400) ? LogLevel.Information : LogLevel.Error);\n```\n\nYou might as well have both custom configuration section and a log level selector.\n\n```csharp\napp.UseRequestLogging(\"YourCustomSection:CustomSubsectionRequestLoging\",\n    statusCode =\u003e (statusCode \u003c 400) ? LogLevel.Information : LogLevel.Error);\n```\n\n### Properties\n\n- Method\n- Path\n- QueryString\n- Header* - A Pascal case field name will be transformed to Kebab case. Example: HeaderFooBar =\u003e foo-bar\n- Protocol\n- Scheme\n- RemoteIpAddress - If you log this property you might want to consider adding `UseForwardedHeaders()` to your pipeline.\n- Claim* - A Pascal case claim type will be transformed to Kebab case. Example: ClaimFooBar =\u003e foo-bar\n- StatusCode\n- ElapsedMs\n\n## Pipeline placement\n\nYou might want to consider placing SimpleRequestLogger after request-heavy middleware like `UseStaticFiles()`\nif those requests are not interesting for you. Alternatively, you might ignore those via the configuration.\n\nIf SimpleRequestLogger catches an exception, the request will be logged with a status code 500\nand the exception will be rethrown. If you have an error handling middleware that alters the response\nstatus code based on exception type, you should consider adding SimpleRequestLogger before it.\n\n## Self-checks\n\nOn startup, when the middleware is instantiated, the configuration is verified. `MessageTemplate`\nand `IgnorePaths` are checked for validity. Additionally, it is also ensured that the log level selector\ndelegate will not throw for the standard response status codes. In case of a problem with the configuration,\nan `InvalidOperationException` is thrown.\n\n## Additional resources\n\n* [Changelog](https://github.com/yavorfingarov/SimpleRequestLogger/blob/master/CHANGELOG.md)\n\n* [License](https://github.com/yavorfingarov/SimpleRequestLogger/blob/master/LICENSE)\n\n## Help and support\n\nFor bug reports and feature requests, please use the [issue tracker](https://github.com/yavorfingarov/SimpleRequestLogger/issues).\nFor questions, ideas and other topics, please check the [discussions](https://github.com/yavorfingarov/SimpleRequestLogger/discussions).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyavorfingarov%2Fsimplerequestlogger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyavorfingarov%2Fsimplerequestlogger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyavorfingarov%2Fsimplerequestlogger/lists"}