Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gokgokalp/nlog.web.aspnetcore.targets.gelf
Gelf4NLog is an [NLog] target implementation to push log messages to [GrayLog2].
https://github.com/gokgokalp/nlog.web.aspnetcore.targets.gelf
aspnet-core aspnetcore gelf-adapter graylog
Last synced: 11 days ago
JSON representation
Gelf4NLog is an [NLog] target implementation to push log messages to [GrayLog2].
- Host: GitHub
- URL: https://github.com/gokgokalp/nlog.web.aspnetcore.targets.gelf
- Owner: GokGokalp
- License: gpl-3.0
- Created: 2017-06-18T14:29:08.000Z (over 7 years ago)
- Default Branch: develop
- Last Pushed: 2022-12-08T08:56:07.000Z (almost 2 years ago)
- Last Synced: 2024-10-04T00:34:28.843Z (about 1 month ago)
- Topics: aspnet-core, aspnetcore, gelf-adapter, graylog
- Language: C#
- Size: 57.6 KB
- Stars: 7
- Watchers: 5
- Forks: 8
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# NLog.Web.AspNetCore.Targets.Gelf
Gelf4NLog is an [NLog] target implementation to push log messages to [GrayLog2]. It implements the [Gelf] specification and communicates with GrayLog server via UDP.[![NuGet version](https://badge.fury.io/nu/NLog.Web.AspNetCore.Targets.Gelf.svg)](https://badge.fury.io/nu/NLog.Web.AspNetCore.Targets.Gelf)
## History
Code forked from https://github.com/2020Legal/NLog.Targets.Gelf which is a fork from https://github.com/akurdyukov/Gelf4NLog who forked the origonal code from https://github.com/seymen/Gelf4NLogI transformed the project to .NET Core.
## Usage
Use Nuget:```
$ dotnet add package NLog.Web.AspNetCore.Targets.Gelf
```
### Configuration
Here is a sample nlog.config configuration file for graylog:
```xml
```
Options are the following:
* __name:__ arbitrary name given to the target
* __xsi:type:__ set this to "gelf"
* __endpoint:__ the uri pointing to the graylog2 input in the format udp://{IP or host name}:{port} *__note:__ support is currently only for udp transport protocol*
* __facility:__ The graylog2 facility to send log messages
* __sendLastFormatParameter:__ default false. If true last parameter of message format will be sent to graylog as separate field per property
* __gelfVersion:__ default "1.0". Set this to "1.1" in order to use actual GELF message format###Code
```c#
//excerpt from ConsoleRunner
var eventInfo = new LogEventInfo
{
Message = comic.Title,
Level = LogLevel.Info,
};
eventInfo.Properties.Add("Publisher", comic.Publisher);
eventInfo.Properties.Add("ReleaseDate", comic.ReleaseDate);
Logger.Log(eventInfo);
```
or alternatively for simple log messages
```c#
Logger.Info("Simple message {0}", value);
```
or alternatively for use of sendLastFormatParameter
```c#
Logger.Info(comic.Title, new { Publisher = comic.Publisher, ReleaseDate = comic.ReleaseDate });
```
will log Publisher and ReleaseDate as separate fields in Graylog[NLog]: http://nlog-project.org/
[GrayLog2]: http://graylog2.org/
[Gelf]: http://graylog2.org/about/gelf