Giter Site home page Giter Site logo

kevinhillinger / servicefabric-logging-elasticsearch Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 0.0 45 KB

Service Fabric + asp.net core to Elasticsearch + Kibana. AService Fabric Stateless Service logging to elasticsearch

License: GNU General Public License v3.0

PowerShell 21.83% C# 62.10% HTML 16.07%

servicefabric-logging-elasticsearch's Introduction

Service Fabric Logging

Today there seems to be a lot of "adapting" that must be done to hook into the logging APIs exposed in the different platforms. Logging, while straight forward (to me anyway), can often require composing various bits together to produce the "right setup"; in this case Service Fabric and Stateless/Stateful Service logging. This example aims to demonstrate one way hooking things up. My intention is to jog your mind toward laying out a full fledged implementation of your own.

Components Overview

  • ServiceFabric (Service Fabric Service)
  • ASP.NET Core (Weblistener) targeting .NET Framework 4.6.1
  • Serilog
  • EventFlow (The Microsoft Diagnostic one; not to be confused with the component for event sourcing)
  • Elasticsearch + Kibana

Overview

The "root" for the logging is Serilog. I chose Serilog because of the following:

  • Decouple logging from ASP.NET Core
  • Flexible enrichment capabilities
  • Configurable through code and XML/JSON configuration

Why Elasticsearch?

Elasticsearch gave the most open ended indexing capabilities, and didn't "artificially" limit the amount of events pushed to the data store. Need more capacity? Then increase the ES deployment capacity.

deployment

Deployment of Elasticsearch and Kibana is on a single VM using Docker. I borrowed the Resource Manager template directly from azure-quickstart-templates

Important Packages (NuGet)

Serilog

  • Serilog
  • Serilog.Extensions.Logging
  • Serilog.Settings.Configuration
  • Serilog.Sinks.Literate

EventFlow

  • Microsoft.Diagnostics.EventFlow
  • Microsoft.Diagnostics.EventFlow.ServiceFabric
  • Microsoft.Diagnostics.EventFlow.Inputs.Etw
  • Microsoft.Diagnostics.EventFlow.Inputs.EventSource
  • Microsoft.Diagnostics.EventFlow.Inputs.Serilog
  • Microsoft.Diagnostics.EventFlow.Outputs.ElasticSearch
  • Microsoft.Diagnostics.EventFlow.Outputs.StdOutput

Guidance / Commentary

Serilog

When using Serilog for a SF Service, do NOT use the "global" Log.Logger. As noted here:

Service Fabric can host multiple instances of the same service type within a single process. If you use the static Log.Logger, the last writer of the property enrichers will show values for all instances that are running. This is one reason why the _logger variable is a private member variable of the service class. Also, you must make the _logger available to common code, which might be used across services.

It's not complex to figure out how NOT to do this. However, the code in LoggingConfigurator and Program show how I did this.

ASP.NET Core

Logging's cross-cutting concern should guide you away from coupling your code to anything ASP.NET Core.

Logging middleware

But given we're trying to capture all HTTP requests going through it, Serilog is adapted into it, and logging Middleware was created. The Middleware does the following:

  • Logs all HTTP requests (any verb) including the request/response payload
  • Logs exceptions occuring in any controller
  • Centralizes the hook into handling exceptions and setting the appropriate status code: 403, 404, 500, etc.

Credit to Nicholas Blumhardt's post for Seq on the Middleware groundwork it laid for me.

servicefabric-logging-elasticsearch's People

Contributors

kevinhillinger avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.