Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce option to enable HTTP logging #176

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion docs/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ This can be useful if you are hosting a private feed and need to host large pack
## Statistics

On the application's statistics page the currently used services and overall package and version counts are listed.
You can hide or show this page by modifying the `EnableStatisticsPage` configuration.
You can hide or show this page by modifying the `EnableStatisticsPage` configuration.
If you set `ListConfiguredServices` to `false` the currently used services for database and storage (such as `Sqlite`) are omitted on the stats page:

```json
Expand Down Expand Up @@ -281,6 +281,13 @@ The specified file `./secrets/api-key.txt` contains the clear text api key only.

The port mapping will make available the service at `http://localhost:5000`. (To make it available using `https` you should use an additional reverse proxy service, like "apache" or "nginx".)

To enable HTTP protocol on the docker Console you can add the following variable:

```yaml
environment:
- Logging__Console__LogLevel__Microsoft.AspNetCore.HttpLogging.HttpLoggingMiddleware=Information
```

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a section specifically about how to load secrets from a file. Please make a new chapter ## Logging, maybe directly under ##Statistics just before the secret loading chapter.

Instead of targeting the `latest` version you may also refer to tags for major, minor and fixed releases, e.g. `1`, `1.4` or `1.4.8`.

Aditional documentation for secrets:
Expand Down
18 changes: 18 additions & 0 deletions src/BaGetter/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using BaGetter.Web;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpLogging;
using Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -24,6 +25,18 @@ public Startup(IConfiguration configuration)

public void ConfigureServices(IServiceCollection services)
{
// configure logging of HTTP requests
services.AddHttpLogging(logging =>
{
logging.LoggingFields = HttpLoggingFields.RequestPath |
HttpLoggingFields.RequestQuery |
HttpLoggingFields.RequestMethod |
HttpLoggingFields.ResponseStatusCode;
logging.CombineLogs = true;
logging.RequestHeaders.Clear();
logging.ResponseHeaders.Clear();
});

services.ConfigureOptions<ValidateBaGetterOptions>();
services.ConfigureOptions<ConfigureBaGetterServer>();

Expand Down Expand Up @@ -77,6 +90,11 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseStatusCodePages();
}

// activate HTTP logging option
// The default severity on the Console is currently "Warning".
// So, the logging is not visible by default but can be easily activated using environment variable.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't warnings and errors still get logged by default? So "most of the logging..." would be more accurate.

app.UseHttpLogging();

app.UseForwardedHeaders();
app.UsePathBase(options.PathBase);

Expand Down
4 changes: 4 additions & 0 deletions src/BaGetter/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
"LogLevel": {
"Microsoft.Hosting.Lifetime": "Information",
"Default": "Warning"
},
"FormatterName": "simple",
"FormatterOptions": {
"SingleLine": true
}
}
},
Expand Down