Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/datalust/nlog-targets-seq
An NLog target that writes events to Seq. Built for NLog 4.5+.
https://github.com/datalust/nlog-targets-seq
nlog nlog-target seq
Last synced: 7 days ago
JSON representation
An NLog target that writes events to Seq. Built for NLog 4.5+.
- Host: GitHub
- URL: https://github.com/datalust/nlog-targets-seq
- Owner: datalust
- License: apache-2.0
- Created: 2017-02-12T23:08:32.000Z (almost 8 years ago)
- Default Branch: dev
- Last Pushed: 2024-10-27T19:25:08.000Z (17 days ago)
- Last Synced: 2024-10-27T23:54:05.645Z (17 days ago)
- Topics: nlog, nlog-target, seq
- Language: C#
- Homepage: https://getseq.net
- Size: 373 KB
- Stars: 21
- Watchers: 7
- Forks: 11
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# NLog.Targets.Seq [![NuGet Pre Release](https://img.shields.io/nuget/vpre/NLog.Targets.Seq.svg)](https://nuget.org/packages/NLog.Targets.Seq) [![Build status](https://ci.appveyor.com/api/projects/status/o22e6dq0mkftaggc?svg=true)](https://ci.appveyor.com/project/datalust/nlog-targets-seq)
An NLog target that writes events to [Seq](https://datalust.co/seq). The target takes full advantage of the structured logging support in **NLog 4.5** to provide hassle-free filtering, searching and analysis.
### Getting started
After installing NLog, install the _NLog.Targets.Seq_ package from NuGet:
```
dotnet add package NLog.Targets.Seq
```Then, add the target and rules entries to your NLog configuration:
```xml
```
The `BufferingWrapper` ensures that writes to Seq do not block the application.
Set the `serverUrl` value to the address of your Seq server, and provide an API key if you have one set up.
A complete sample application and _NLog.config_ file can be found [here in this repository](https://github.com/datalust/nlog-targets-seq/tree/dev/sample/Example).
### Structured logging with NLog
NLog 4.5 adds support for [message templates](https://messagetemplates.org), extended format strings that capture first-class properties along with the usual message text.
```csharp
var logger = LogManager.GetCurrentClassLogger();for (var i = 0; i < 10; ++i)
{
logger.Info("Hello, {Name}, on iteration {Counter}", Environment.UserName, i);
}
```When the events logged in this snippet are rendered to a file or console, they'll appear just like regular formatted text. In Seq or another structured log data store, you'll see that the original `Name` and `Counter` values are preserved separately:
![EventsInSeq](https://raw.githubusercontent.com/datalust/nlog-targets-seq/dev/asset/nlog-events-in-seq.png)
This makes filtering with expressions such as `Counter > 8` or `Name like 'nb%'` trivial: no regular expressions or log parsing are needed to recover the original values.
The fully-rendered message is there too, so you can still search for text like `"Hello, nblumhardt"` and find the events you'd expect.
### Attaching additional properties
The `target` declaration in _NLog.config_ can be expanded with additional properties:
```xml
```Any properties specified here will be attached to all outgoing events. You can see examples of `ThreadId` and `MachineName` in the screenshot above. The value can be any supported [layout renderer](https://github.com/NLog/NLog/wiki/Layout-Renderers).
### Configuration in appsettings.json
NLog.Extensions.Logging ver. 1.5.0 adds support for having [NLog configuration in appsettings.json](https://github.com/NLog/NLog.Extensions.Logging/wiki/NLog-configuration-with-appsettings.json)
```json
{
"NLog": {
"throwConfigExceptions": true,
"extensions": [
{ "assembly": "NLog.Targets.Seq" }
],
"targets": {
"seq": {
"type": "BufferingWrapper",
"bufferSize": 200,
"flushTimeout": 2000,
"slidingTimeout": false,
"target": {
"type": "Seq",
"serverUrl": "http://localhost:5341",
"apiKey": "",
"properties": [
{
"name": "Source",
"value": "${Logger}"
},
{
"name": "ThreadId",
"value": "${ThreadId}",
"as": "number"
},
{
"name": "MachineName",
"value": "${MachineName}"
}]
}
}
},
"rules": [
{
"logger": "*",
"minLevel": "Info",
"writeTo": "seq"
}]
}
}
```### Acknowledgements
The target is based on the earlier [_Seq.Client.NLog_ project](https://github.com/datalust/seq-client), and benefits from many contributions accepted into that repository.