All Projects β†’ datalust β†’ Seq Extensions Logging

datalust / Seq Extensions Logging

Licence: apache-2.0
Add centralized log collection to ASP.NET Core apps with one line of code.

Projects that are alternatives of or similar to Seq Extensions Logging

Awesome Microservices Netcore
πŸ’Ž A collection of awesome training series, articles, videos, books, courses, sample projects, and tools for Microservices in .NET Core
Stars: ✭ 865 (+1417.54%)
Mutual labels:  aspnetcore
Aspnetcore Tests Sample
A project to help demonstrate how to do unit, integration and acceptance tests with an web api project using ASP.NET Core and Angular 7 front end.
Stars: ✭ 40 (-29.82%)
Mutual labels:  aspnetcore
Couchdb Net
EF Core-like CouchDB experience for .NET!
Stars: ✭ 50 (-12.28%)
Mutual labels:  aspnetcore
Prometheus Net
.NET library to instrument your code with Prometheus metrics
Stars: ✭ 944 (+1556.14%)
Mutual labels:  aspnetcore
Run Aspnetcore Angular retired
Enterprise Web Application infrastructure for ASP.NET Core and Angular. Boilerplate for ASP.NET Core + Angular reference application, demonstrating a layered application architecture with DDD best practices. Download 100+ page eBook PDF from here ->
Stars: ✭ 36 (-36.84%)
Mutual labels:  aspnetcore
Httpreports
HttpReports is an APM (application performance monitor) system for .Net Core.
Stars: ✭ 1,009 (+1670.18%)
Mutual labels:  aspnetcore
Lettuceencrypt
Free, automatic HTTPS certificate generation for ASP.NET Core web apps
Stars: ✭ 939 (+1547.37%)
Mutual labels:  aspnetcore
Blazorcomponents
Simple reusable Blazor component library
Stars: ✭ 53 (-7.02%)
Mutual labels:  aspnetcore
Saunter
Saunter is a code-first AsyncAPI documentation generator for dotnet.
Stars: ✭ 39 (-31.58%)
Mutual labels:  aspnetcore
Easycaching
πŸ’₯ EasyCaching is an open source caching library that contains basic usages and some advanced usages of caching which can help us to handle caching more easier!
Stars: ✭ 1,047 (+1736.84%)
Mutual labels:  aspnetcore
Practical Clean Ddd
A simplified and effortless approach to get started with Domain-driven Design, Clean Architecture, CQRS, and Microservices patterns
Stars: ✭ 28 (-50.88%)
Mutual labels:  aspnetcore
Server
The core infrastructure backend (API, database, Docker, etc).
Stars: ✭ 8,797 (+15333.33%)
Mutual labels:  aspnetcore
Buildingblocks
Building blocks for Aspnet Core Microservices Development
Stars: ✭ 43 (-24.56%)
Mutual labels:  aspnetcore
Litecodecore
基于asp.net Core εŸΊη‘€ζƒι™η³»η»Ÿ
Stars: ✭ 13 (-77.19%)
Mutual labels:  aspnetcore
Aspnetcore Request Decompression
HTTP request decompression middleware for ASP.NET Core
Stars: ✭ 51 (-10.53%)
Mutual labels:  aspnetcore
Csla
A home for your business logic in any .NET application.
Stars: ✭ 865 (+1417.54%)
Mutual labels:  aspnetcore
Znetcs.aspnetcore.authentication.basic
A simple basic authentication middleware.
Stars: ✭ 40 (-29.82%)
Mutual labels:  aspnetcore
Vuejs Aspnetcore Ssr
πŸ†™ VueJS 2.5 Server Side Rendering on ASP.NET Core 2 and more
Stars: ✭ 57 (+0%)
Mutual labels:  aspnetcore
Proxykit
A toolkit to create code-first HTTP reverse proxies on ASP.NET Core
Stars: ✭ 1,063 (+1764.91%)
Mutual labels:  aspnetcore
Danvic.psu
This is my graduation project of dotnet core version
Stars: ✭ 46 (-19.3%)
Mutual labels:  aspnetcore

Seq.Extensions.Logging Build status NuGet Pre Release Join the chat at https://gitter.im/datalust/seq

Seq is a flexible self-hosted back-end for the ASP.NET Core logging subsystem (Microsoft.Extensions.Logging). Log events generated by the framework and application code are sent over HTTP to a Seq server, where the structured data associated with each event is used for powerful filtering, correlation, and analysis.

For an example, see the dotnetconf deep dive session.

Screenshot

This package makes it a one-liner to configure ASP.NET Core logging with Seq.

Getting started

The instructions that follow are for .NET Core 2.0+.

Add the NuGet package to your project either by editing the CSPROJ file, or using the NuGet package manager:

dotnet add package Seq.Extensions.Logging

In Startup.cs, call AddSeq() on the provided ILoggingBuilder.

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        // Added; requires `using Microsoft.Extensions.Logging;`
        services.AddLogging(builder => builder.AddSeq())

        // Other configuration follows...
    }
}

The framework will inject ILogger instances into controllers and other classes:

class HomeController : Controller
{
    readonly ILogger<HomeController> _log;
    
    public HomeController(ILogger<HomeController> log)
    {
        _log = log;
    }
    
    public IActionResult Index()
    {
        _log.LogInformation("Hello, world!");
    }
}

Log messages will be sent to Seq in batches and be visible in the Seq user interface. Observe that correlation identifiers added by the framework, like RequestId, are all exposed and fully-searchable in Seq.

Logging with message templates

Seq supports the templated log messages used by Microsoft.Extensions.Logging. By writing events with named format placeholders, the data attached to the event preserves the individual property values.

var fizz = 3, buzz = 5;
log.LogInformation("The current values are {Fizz} and {Buzz}", fizz, buzz);

This records an event like:

Property Value
Message "The current values are 3 and 5"
Fizz 3
Buzz 5

Seq makes these properties searchable without additional log parsing. For example, a filter expression like Fizz < 4 would match the event above.

Additional configuration

The AddSeq() method exposes some basic options for controlling the connection and log volume.

Parameter Description Example value
apiKey A Seq API key to authenticate or tag messages from the logger "1234567890"
levelOverrides A dictionary mapping logger name prefixes to minimum logging levels new Dictionary<string,LogLevel>{ ["Microsoft"] = LogLevel.Warning }
minimumLevel The level below which events will be suppressed (the default is Information) LogLevel.Trace

JSON configuration

The logging level, Seq server URL, API key and other settings can be read from JSON configuration if desired.

In appsettings.json add a "Seq" property to "Logging" to configure the server URL, API key, and levels for the Seq provider:

{
  "Logging": {
    "LogLevel": {
      "Default": "Information"
    },
    "Seq": {
      "ServerUrl": "http://localhost:5341",
      "ApiKey": "1234567890",
      "LogLevel": {
        "System": "Information",
        "Microsoft": "Warning"
      }
    }
  }
}

Dynamic log level control

The logging provider will dynamically adjust the default logging level up or down based on the level associated with an API key in Seq. For further information see the Seq documentation.

Troubleshooting

Nothing showed up, what can I do?

If events don't appear in Seq after pressing the refresh button in the filter bar, either your application was unable to contact the Seq server, or else the Seq server rejected the log events for some reason.

Server-side issues

The Seq server may reject incoming events if they're missing a required API key, if the payload is corrupted somehow, or if the log events are too large to accept.

Server-side issues are diagnosed using the Seq Ingestion Log, which shows the details of any problems detected on the server side. The ingestion log is linked from the Settings > Diagnostics page in the Seq user interface.

Client-side issues

If there's no information in the ingestion log, the application was probably unable to reach the server because of network configuration or connectivity issues. These are reported to the application through SelfLog.

Add the following line after the logger is configured to print any error information to the console:

Seq.Extensions.Logging.SelfLog.Enable(Console.Error);

If the console is not available, you can pass a delegate into SelfLog.Enable() that will be called with each error message:

Seq.Extensions.Logging.SelfLog.Enable(message => {
    // Do something with `message`
});

Troubleshooting checklist

  • Check the Seq Ingestion Log, as described in the Server-side issues section above.
  • Turn on the SelfLog as described above to check for connectivity problems and other issues on the client side.
  • Raise an issue, ask for help on the Seq support forum or email [email protected].

Migrating to Serilog

This package is based on a subset of the powerful Serilog library. Not all of the options supported by the Serilog and Seq client libraries are present in the Seq.Extensions.Logging package. Migrating to the full Serilog API however is very easy:

  1. Install packages Serilog, Serilog.Extensions.Logging and Serilog.Sinks.Seq.
  2. Follow the instructions here to change AddSeq() into AddSerilog() with a LoggerConfiguration object passed in
  3. Add WriteTo.Seq() to the Serilog configuration as per the example given for the Seq sink for Serilog
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].