Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwcole committed Feb 5, 2019
1 parent dc47c88 commit 5391521
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@

The following examples are for ASP.NET Core. The [samples](/samples) directory contains example console apps with and without ASP.NET Core. For more information on providers and logging in general, see the aspnetcore [logging documentation](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging?tabs=aspnetcore2x#how-to-add-providers).

Start by installing the [NuGet package](https://www.nuget.org/packages/Gelf.Extensions.Logging).

```sh
dotnet add package Gelf.Extensions.Logging
```

### ASP.NET Core 2.x

In `Program.cs`, import the `LoggingBuilder.AddGelf()` extension method from `Gelf.Extensions.Logging` and add the following to your `WebHost` configuration.
Expand Down Expand Up @@ -46,9 +52,9 @@ Logger options are taken from the "GELF" provider section in `appsettings.json`
},
"GELF": {
"Host": "localhost",
"Port": 12201, // Not required if using default 12201.
"LogSource": "my-app-name", // Required if not set in code.
"AdditionalFields": { // Optional fields added to all logs.
"Port": 12201, // Not required if using default 12201.
"LogSource": "my-app-name", // Not required if set in code.
"AdditionalFields": { // Optional fields added to all logs.
"project_name": "my-project-name"
},
"LogLevel": {
Expand Down Expand Up @@ -138,6 +144,14 @@ In the example above, the message will contain an `order_id` and `order_time`.

When using .NET Core 2.x, the log filtering API should be used to filter the "GELF" provider (details [here](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging?tabs=aspnetcore2x#log-filtering)). In .NET Core 1.x, log filtering can be overridden by setting a custom filter with `GelfLoggerOptions.Filter`, overriding the default filter that uses `GelfLoggerOptions.LogLevel`.

### Compression

By default UDP messages of 512 bytes or more are GZipped however this behaviour can be disabled or altered with `GelfLoggerOptions.CompressUdp` and `GelfLoggerOptions.UdpCompressionThreshold`.

#### Logstash GELF Plugin

The [Logstash GELF plugin](https://www.elastic.co/guide/en/logstash/current/plugins-inputs-gelf.html) requires entirely compressed UDP messages in which case the UDP compression threshold must be set to 0.

### Testing

This repository contains a Docker Compose file that can be used for creating local a Graylog stack with a single command using the [Graylog Docker image](https://hub.docker.com/r/graylog/graylog/). This can be useful for testing application logs locally. Requires [Docker](https://www.docker.com/get-docker) and Docker Compose.
Expand Down

0 comments on commit 5391521

Please sign in to comment.