• Stars
    star
    161
  • Rank 226,101 (Top 5 %)
  • Language
    C#
  • License
    Apache License 2.0
  • Created over 7 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Serilog sink sending log events over HTTP.

Serilog.Sinks.Http - A Serilog sink sending log events over HTTP

Build status codecov NuGet Version SemVer compatible NuGet Documentation Join the chat at https://gitter.im/serilog/serilog Help

Package - Serilog.Sinks.Http | Platforms - .NET 4.5/4.6.1, .NET Standard 2.0/2.1

Table of contents


Introduction

This project started out with a wish to send log events to the Elastic Stack. I had prior experience of Elastic Filebeat and didn't like it. I thought the value it added was lower than the complexity it introduced.

Knowing that Serilog.Sinks.Seq existed, and knowing that the code was of really good quality, I blatantly copied many of the core files into this project and started developing a general HTTP sink.

And here we are today. I hope you'll find the sink useful. If not, don't hesitate to open an issue.

Super simple to use

In the following example, the sink will POST log events to http://www.mylogs.com over HTTP. We configure the sink using named arguments instead of positional because historically we've seen that most breaking changes where the result of a new parameter describing a new feature. Using named arguments means that you more often than not can migrate to new major versions without any changes to your code.

ILogger log = new LoggerConfiguration()
  .MinimumLevel.Verbose()
  .WriteTo.Http(requestUri: "https://www.mylogs.com", queueLimitBytes: null)
  .CreateLogger();

log.Information("Logging {@Heartbeat} from {Computer}", heartbeat, computer);

Used in conjunction with Serilog.Settings.Configuration the same sink can be configured in the following way:

{
  "Serilog": {
    "MinimumLevel": "Verbose",
    "WriteTo": [
      {
        "Name": "Http",
        "Args": {
          "requestUri": "https://www.mylogs.com",
          "queueLimitBytes": null
        }
      }
    ]
  }
}

The sink can also be configured to be durable, i.e. log events are persisted on disk before being sent over the network, thus protected against data loss after a system or process restart. For more information please read the wiki.

The sink is batching multiple log events into a single request, and the following hypothetical payload is sent over the network as JSON.

[
  {
    "Timestamp": "2016-11-03T00:09:11.4899425+01:00",
    "Level": "Information",
    "MessageTemplate": "Logging {@Heartbeat} from {Computer}",
    "RenderedMessage": "Logging { UserName: \"Mike\", UserDomainName: \"Home\" } from \"Workstation\"",
    "Properties": {
      "Heartbeat": {
        "UserName": "Mike",
        "UserDomainName": "Home"
      },
      "Computer": "Workstation"
    }
  },
  {
    "Timestamp": "2016-11-03T00:09:12.4905685+01:00",
    "Level": "Information",
    "MessageTemplate": "Logging {@Heartbeat} from {Computer}",
    "RenderedMessage": "Logging { UserName: \"Mike\", UserDomainName: \"Home\" } from \"Workstation\"",
    "Properties": {
      "Heartbeat": {
        "UserName": "Mike",
        "UserDomainName": "Home"
      },
      "Computer": "Workstation"
    }
  }
]

Typical use cases

Producing log events is only half the story. Unless you are consuming them in a matter that benefits you in development or production, there is really no need to produce them in the first place.

Integration with Elastic Stack (formerly know as ELK, an acronym for Elasticsearch, Logstash and Kibana) is powerful beyond belief, but there are many alternatives to get the log events into Elasticsearch.

Send log events from Docker containers

A common solution, given your application is running in Docker containers, is to have stdout (standard output) and stderr (standard error) passed on to the Elastic Stack. There is a multitude of ways to accomplish this, but one using Logspout is linked in the Sample applications chapter.

Send log events to Elasticsearch

The log events can be sent directly to Elasticsearch using Serilog.Sinks.Elasticsearch. In this case you've solved your problem without using this sink, and all is well in the world.

Send log events to Logstash

If you would like to send the log events to Logstash for further processing instead of sending them directly to Elasticsearch, this sink in combination with the Logstash HTTP input plugin is the perfect match for you. It is a much better solution than having to install Filebeat on all your instances, mainly because it involves fewer moving parts.

Sample applications

The following sample applications demonstrate the usage of this sink in various contexts:

The following sample application demonstrate how Serilog events from a Docker container end up in the Elastic Stack using Logspout, without using Serilog.Sinks.Http.

Install via NuGet

If you want to include the HTTP sink in your project, you can install it directly from NuGet.

To install the sink, run the following command in the Package Manager Console:

PM> Install-Package Serilog.Sinks.Http

Contributors

The following users have made significant contributions to this project. Thank you so much!

JetBrains
JetBrains

πŸš‡
C. Augusto Proiete
C. Augusto Proiete

πŸ’΅ πŸ’¬ πŸ’» πŸ€”
Louis Haußknecht
Louis Haußknecht

πŸ’» πŸ€” πŸ›
rob-somerville
rob-somerville

πŸ’» πŸ€” πŸ›
Kevin Petit
Kevin Petit

πŸ’» πŸ€” πŸ›
aleksaradz
aleksaradz

πŸ’» πŸ€” πŸ›
michaeltdaniels
michaeltdaniels

πŸ€”
dusse1dorf
dusse1dorf

πŸ€”
vaibhavepatel
vaibhavepatel

πŸ› πŸ’» πŸ€”
KalininAndreyVictorovich
KalininAndreyVictorovich

πŸ› πŸ’»
Sergios
Sergios

πŸ›
Anton Smolkov
Anton Smolkov

πŸ’» πŸ›
Michael J Conrad
Michael J Conrad

πŸ“–
Yuriy Sountsov
Yuriy Sountsov

πŸ€”
Yuriy Millen
Yuriy Millen

πŸ’» πŸ€”

More Repositories

1

mvvm-dialogs

Library simplifying the concept of opening dialogs from a view model when using MVVM in WPF
C#
613
star
2

aws-signature-version-4

The buttoned-up and boring, but deeply analyzed, implementation of SigV4 in .NET
C#
74
star
3

action-update-license-year

GitHub Action that in a pull request updates the copyright year(s) in your license file.
JavaScript
52
star
4

serilog-sinks-udp

A Serilog sink sending UDP packages over the network.
C#
28
star
5

serilog-sinks-http-sample-elastic-stack

Sample application of Serilog.Sinks.Http sending log events to Elastic Stack.
C#
17
star
6

axis-js

A collection of Node.js packages written in TypeScript, helping you to interact with network cameras from Axis Communication.
TypeScript
14
star
7

searchlight

A cross-platform desktop application discovering Axis network video devices on your network
TypeScript
13
star
8

serilog-sinks-http-sample-dotnet-core

Sample application of Serilog.Sinks.Http producing log events in .NET Core.
C#
11
star
9

axis-discovery-ssdp-js

A Node.js SSDP (UPnP) client library written in TypeScript capable of searching for Axis Communication cameras.
TypeScript
8
star
10

mvvm-dialogs-integrated-into-windows-community-toolkit

MVVM Dialogs integrated into CommunityToolkit.Mvvm
C#
8
star
11

todo-cqrs

TodoMVC implementations using CQRS and event sourcing.
C#
7
star
12

expect

A Node.js library written in TypeScript providing argument validation.
TypeScript
5
star
13

mvvm-dialogs-integrated-into-caliburn-micro

MVVM Dialogs integrated into Caliburn.Micro
C#
4
star
14

axis-discovery-js

A Node.js client library written in TypeScript capable of searching for Axis Communication cameras using Bonjour and SSDP (UPnP).
TypeScript
4
star
15

mvvm-dialogs-integrated-into-mvvm-light-toolkit

MVVM Dialogs integrated into MVVM Light Toolkit
C#
3
star
16

teamcity-backup

A tool helping you to backup all your TeamCity projects and their settings.
C#
3
star
17

mvvm-dialogs-contrib

Features and functionality complementing MVVM Dialogs
C#
3
star
18

serilog-sinks-udp-sample-dotnet-core

Sample application of Serilog.Sinks.Udp producing log events in .NET Core.
C#
3
star
19

web-server-tech-benchmark

Project comparing the performance of web servers implemented in a small subset of programming languages.
C#
2
star
20

sandbox-hateoas

A HATEOAS playground suitable for a software developer.
C#
2
star
21

sandbox

A playground suitable for a software developer.
JavaScript
1
star
22

wpf-branding

C#
1
star
23

course-akka.net-bootcamp

A course in Akka.NET.
C#
1
star
24

renovate-config

Configuration file for Renovate (https://renovatebot.com/)
1
star
25

axis-configuration-js

A Node.js library written in TypeScript capable of configuring Axis Communication cameras.
TypeScript
1
star
26

namecheap-dynamic-dns-client

C#
1
star
27

axis-discovery-bonjour-js

A Node.js Bonjour client library written in TypeScript capable of searching for Axis Communication cameras.
TypeScript
1
star
28

certifications

Repository related to certifications
1
star
29

console-in-docker

A library helping .NET developers to build console applications in Docker.
PowerShell
1
star
30

FantasticFiasco

1
star
31

axis-maintenance-js

A Node.js library written in TypeScript capable of running maintenance operations on cameras from Axis Communication.
TypeScript
1
star
32

axis-snapshot-js

A Node.js library written in TypeScript capable of getting snapshots from Axis Communication cameras.
TypeScript
1
star
33

guid-generator

A replacement for the Visual Studio GUID Generator.
C#
1
star
34

serilog-sinks-http-sample-fluentd

Sample application of Serilog.Sinks.Http sending log events to Fluentd.
C#
1
star