All Projects → RehanSaeed → Serilog.exceptions

RehanSaeed / Serilog.exceptions

Licence: mit
Log exception details and custom properties that are not output in Exception.ToString().

Programming Languages

reflection
70 projects

Projects that are alternatives of or similar to Serilog.exceptions

Dotnetcore
.NET 5 Nuget Packages.
Stars: ✭ 146 (-48.23%)
Mutual labels:  logging, nuget, dotnet-core
Bridge
♠️ C# to JavaScript compiler. Write modern mobile and web apps in C#. Run anywhere with Bridge.NET.
Stars: ✭ 2,216 (+685.82%)
Mutual labels:  nuget, dotnet-core
Liget
NuGet server and cache running on kestrel in docker
Stars: ✭ 177 (-37.23%)
Mutual labels:  nuget, dotnet-core
Pioneer Console Boilerplate
Dependency injection, logging and configuration in a .NET Core console application.
Stars: ✭ 60 (-78.72%)
Mutual labels:  logging, dotnet-core
Colore
A powerful C# library for Razer Chroma's SDK
Stars: ✭ 121 (-57.09%)
Mutual labels:  nuget, dotnet-core
Ether.network
https://github.com/Eastrall/Sylver
Stars: ✭ 147 (-47.87%)
Mutual labels:  nuget, dotnet-core
Templates
.NET project templates with batteries included, providing the minimum amount of code required to get you going faster.
Stars: ✭ 2,864 (+915.6%)
Mutual labels:  nuget, dotnet-core
Publish Nuget
📦 GitHub action to automate publishing NuGet packages when project version changes
Stars: ✭ 109 (-61.35%)
Mutual labels:  nuget, dotnet-core
Log4net.elasticsearch
log4net appender to ElasticSearch
Stars: ✭ 202 (-28.37%)
Mutual labels:  logging, nuget
Easy.logger
A modern, high performance cross platform wrapper for Log4Net.
Stars: ✭ 118 (-58.16%)
Mutual labels:  logging, dotnet-core
Recaptcha.aspnetcore
Google reCAPTCHA v2/v3 for .NET Core 3.x
Stars: ✭ 122 (-56.74%)
Mutual labels:  nuget, dotnet-core
Hangfire.JobsLogger
A Hangfire extension to store a log during job execution.
Stars: ✭ 21 (-92.55%)
Mutual labels:  nuget, logging
Kafka Flow
KafkaFlow is a .NET framework to consume and produce Kafka messages with multi-threading support. It's very simple to use and very extendable. You just need to install, configure, start/stop the bus with your app and create a middleware/handler to process the messages.
Stars: ✭ 118 (-58.16%)
Mutual labels:  nuget, dotnet-core
Stock.indicators
Stock indicator technical analysis library package for .NET. Send in historical price quotes and get back desired technical indicators. Nothing more. It can be used in any market analysis software using standard OHLCV price quotes for equities, commodities, forex, cryptocurrencies, and others. We had private trading algorithms, machine learning, and charting systems in mind when originally creating this community library. Current indicators include: Accumulation/Distribution Line (ADL), Aroon Oscillator, Arnaud Legoux Moving Average (ALMA), Average Directional Index (ADX), Average True Range (ATR), Awesome Oscillator (AO), Balance of Power (BOP), Beta Coefficient, Bollinger Bands®, Chaikin Money Flow (CMF), Chaikin Oscillator, Chandelier Exit, Choppiness Index (CHOP), Commodity Channel Index (CCI), ConnorsRSI, Correlation Coefficient, Donchian Channels, Double Exponential Moving Average (DEMA), Elder-ray Index, Exponential Moving Average (EMA), Force Index, Fractal Chaos Bands (FCB), Gator Oscillator, Heikin-Ashi, Hull Moving Average (HMA), Ichimoku Cloud, Kaufman's Adaptive Moving Average (KAMA), KDJ Index, Keltner Channels, Momentum Oscillator, Money Flow Index (MFI), MESA Adaptive Moving Averages (MAMA), Moving Average Convergence/Divergence (MACD), Moving Average Envelopes, On-balance Volume (OBV), Parabolic SAR (stop and reverse), Percentage Volume Oscillator (PVO), Pivot Points and Rolling Pivot Points, Price Channels, Price (Comparative) Relative Strength (PRS), Price Momentum Oscillator (PMO), Rate of Change (ROC), Relative Strength Index (RSI), R-Squared (Coefficient of Determination), Simple Moving Average (SMA), Slope and Linear Regression, Smoothed Moving Average (SMMA), Standard Deviation, Stoller Average Range Channel (STARC) Bands, Stochastic Oscillator, Stochastic RSI, SuperTrend, Tillson T3 Moving Average, Triple Exponential Moving Average (TEMA), Triple EMA Oscillator (TRIX), True Strength Index (TSI), Ulcer Index, Ultimate Oscillator, Volume Simple Moving Average, Volume Weighted Average Price (VWAP), Vortex Indicator (VI), Weighted Moving Average (WMA), Williams %R, Williams Alligator, Williams Fractal, and Zig Zag.
Stars: ✭ 157 (-44.33%)
Mutual labels:  nuget, dotnet-core
Dotnet Tools
A list of tools to extend the .NET Core command line (dotnet)
Stars: ✭ 1,551 (+450%)
Mutual labels:  nuget, dotnet-core
Mond
A scripting language for .NET Core
Stars: ✭ 237 (-15.96%)
Mutual labels:  nuget, dotnet-core
Computesharp
A .NET 5 library to run C# code in parallel on the GPU through DX12 and dynamically generated HLSL compute shaders, with the goal of making GPU computing easy to use for all .NET developers! 🚀
Stars: ✭ 982 (+248.23%)
Mutual labels:  nuget, dotnet-core
Brighter
Command Dispatcher, Processor, and Distributed Task Queue
Stars: ✭ 1,393 (+393.97%)
Mutual labels:  nuget, dotnet-core
Xunit Logging
Logging extensions for xunit
Stars: ✭ 69 (-75.53%)
Mutual labels:  logging, dotnet-core
logging
Generic file logger for .NET Core (FileLoggerProvider) with minimal dependencies
Stars: ✭ 109 (-61.35%)
Mutual labels:  logging, dotnet-core

Schema.NET Banner

NuGet Package Serilog.Exceptions package in serilog-exceptions feed in Azure Artifacts Twitter URL Twitter Follow

Serilog.Exceptions is an add-on to Serilog to log exception details and custom properties that are not output in Exception.ToString().

What Does It Do?

Your JSON logs will now be supplemented with detailed exception information and even custom exception properties. Here is an example of what happens when you log a DbEntityValidationException from EntityFramework (This exception is notorious for having deeply nested custom properties which are not included in the .ToString()).

try
{
    ...
}
catch (DbEntityValidationException exception)
{
    logger.Error(exception, "Hello World");
}

The code above logs the following:

{
  "Timestamp": "2015-12-07T12:26:24.0557671+00:00",
  "Level": "Error",
  "MessageTemplate": "Hello World",
  "RenderedMessage": "Hello World",
  "Exception": "System.Data.Entity.Validation.DbEntityValidationException: Message",
  "Properties": {
    "ExceptionDetail": {
      "EntityValidationErrors": [
        {
          "Entry": null,
          "ValidationErrors": [
            {
              "PropertyName": "PropertyName",
              "ErrorMessage": "PropertyName is Required.",
              "Type": "System.Data.Entity.Validation.DbValidationError"
            }
          ],
          "IsValid": false,
          "Type": "System.Data.Entity.Validation.DbEntityValidationResult"
        }
      ],
      "Message": "Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.",
      "Data": {},
      "InnerException": null,
      "TargetSite": null,
      "StackTrace": null,
      "HelpLink": null,
      "Source": null,
      "HResult": -2146232032,
      "Type": "System.Data.Entity.Validation.DbEntityValidationException"
    },
    "Source": "418169ff-e65f-456e-8b0d-42a0973c3577"
  }
}

Getting Started

Add the Serilog.Exceptions NuGet package to your project using the NuGet Package Manager or run the following command in the Package Console Window:

dotnet add package Serilog.Exceptions

When setting up your logger, add the WithExceptionDetails() line like so:

using Serilog;
using Serilog.Exceptions;

ILogger logger = new LoggerConfiguration()
    .Enrich.WithExceptionDetails()
    .WriteTo.RollingFile(
        new JsonFormatter(renderMessage: true), 
        @"C:\logs\log-{Date}.txt")    
    .CreateLogger();

Make sure that the sink's formatter outputs enriched properties. Serilog.Sinks.Console and many more do not do that by default. You may need to add {Properties:j} to your sink's format template. For example, configuration for console sink may look like that:

.WriteTo.Console(outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception} {Properties:j}")

Performance

This library has custom code to deal with extra properties on most common exception types and only falls back to using reflection to get the extra information if the exception is not supported by Serilog.Exceptions internally. Reflection overhead is present but minimal, because all the expensive relection-based operations are done only once per exception-type.

Additional Destructurers

Serilog.Exceptions.SqlServer

NuGet Package Serilog.Exceptions.SqlServer package in serilog-exceptions feed in Azure Artifacts

Add the Serilog.Exceptions.SqlServer NuGet package to your project to avoid the reflection based destructurer for SqlException when using System.Data.SqlClient:

Install-Package Serilog.Exceptions.SqlServer

Add the SqlExceptionDestructurer during setup:

.Enrich.WithExceptionDetails(new DestructuringOptionsBuilder()
    .WithDefaultDestructurers()
    .WithDestructurers(new[] { new SqlExceptionDestructurer() }))

Serilog.Exceptions.MsSqlServer

NuGet Package Serilog.Exceptions.MsSqlServer package in serilog-exceptions feed in Azure Artifacts

Add the Serilog.Exceptions.MsSqlServer NuGet package to your project to avoid the reflection based destructurer for SqlException when using Microsoft.Data.SqlClient:

Install-Package Serilog.Exceptions.MsSqlServer

Add the SqlExceptionDestructurer during setup:

.Enrich.WithExceptionDetails(new DestructuringOptionsBuilder()
    .WithDefaultDestructurers()
    .WithDestructurers(new[] { new SqlExceptionDestructurer() }))

Serilog.Exceptions.EntityFrameworkCore

NuGet Package Serilog.Exceptions.EntityFrameworkCore package in serilog-exceptions feed in Azure Artifacts

WARNING: If you are using EntityFrameworkCore with Serilog.Exceptions you must add this, otherwise in certain cases your entire database will be logged! This is because the exceptions in Entity Framework Core have properties that link to the entire database schema in them (See #100, aspnet/EntityFrameworkCore#15214)

Add the Serilog.Exceptions.EntityFrameworkCore NuGet package to your project when using EntityFrameworkCore in your project

Install-Package Serilog.Exceptions.EntityFrameworkCore

Add the DbUpdateExceptionDestructurer during setup:

.Enrich.WithExceptionDetails(new DestructuringOptionsBuilder()
    .WithDefaultDestructurers()
    .WithDestructurers(new[] { new DbUpdateExceptionDestructurer() }))

Custom Exception Destructurers

You may want to add support for destructuring your own exceptions without relying on reflection. To do this, create your own destructuring class implementing ExceptionDestructurer (You can take a look at this for ArgumentException), then simply add it like so:

.Enrich.WithExceptionDetails(new DestructuringOptionsBuilder()
    .WithDefaultDestructurers()
    .WithDestructurers(new[] { new MyCustomExceptionDestructurer() }))

If you write a destructurer that is not included in this project (even for a third party library), please contribute it.

Additional configuration

You can configure some additional properties of destructuring process, by passing custom destructuring options during setup:

.Enrich.WithExceptionDetails(new DestructuringOptionsBuilder()
    .WithDefaultDestructurers()
    .WithRootName("Exception"))

Currently following options are supported:

  • RootName: The property name which will hold destructured exception, ExceptionDetail by default.
  • Filter: The object implementing IExceptionPropertyFilter that will have a chance to filter properties just before they are put in destructured exception object. Go to "Filtering properties" section for details.
  • DestructuringDepth: The maximum depth of reflection based recursive destructuring process.
  • ReflectionBasedDestructurer: Reflection based destructurer is enabled by default, but can be disabled in case you want to have complete control over destructuring process. You will have to register destructurers for all exceptions explicitly.

Filtering properties

You may want to skip some properties of all or part your exception classes without directly creating or modifying custom destructurers. Serilog.Exceptions supports this functionality using a filter.

Most typical use case is the need to skip StackTrace and TargetSite. Serilog is already reporting them so you may want Serilog.Exceptions to skip them to save space and processing time. To do that you just need to modify a line in configuration:

.Enrich.WithExceptionDetails(new DestructuringOptionsBuilder().WithFilter(someFilter));

Filtering for other scenarios is also supported:

  • Use WithIgnoreStackTraceAndTargetSiteExceptionFilter if you need to filter some other set of named properties
  • Implement custom IExceptionPropertyFilter if you need some different filtering logic
  • Use CompositeExceptionPropertyFilter to combine multiple filters

Continuous Integration

Name Operating System Status History
Azure Pipelines Ubuntu Azure Pipelines Ubuntu Build Status
Azure Pipelines Mac Azure Pipelines Mac Build Status
Azure Pipelines Windows Azure Pipelines Windows Build Status
Azure Pipelines Overall Azure Pipelines Overall Build Status Azure DevOps Build History
GitHub Actions Ubuntu, Mac & Windows GitHub Actions Status GitHub Actions Build History
AppVeyor Ubuntu, Mac & Windows AppVeyor Build Status AppVeyor Build History

Contributions and Thanks

Please view the contributing guide for more information.

  • 304NotModified - Added Markdown syntax highlighting.
  • joelweiss - Added Entity Framework Core destructurers.
  • krajek & JeroenDragt - For adding filters to help ignore exception properties you don't want logged.
  • krajek - For helping with cyclic dependencies when using the reflection destructurer.
  • mraming - For logging properties that throw exceptions.
  • optical - For a huge VS 2017 upgrade PR.
  • Jérémie Bertrand - For making Serilog.Exceptions compatible with Mono.
  • krajek - For writing some much needed unit tests.
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].