serilog

Serilog's ILogger injected using Log.ForContext<T>, where T is the consumer

跟風遠走 提交于 2021-01-20 16:11:26
问题 Serilog allows creating a context-aware logger: Log.ForContext<T>() I would like to register Serilog with SimpleInjector in such a way that T is the type of the consumer, i.e. it is which class it is injected in to. e.g. public class Car { public Car(ILogger logger) <= would be injected using Log.ForContext<Car>() { } } I can see this has been done with AutoFac. And looking through the SimpleInjector documentation, there is a very promising overload of RegisterConditional() (with the Func

Serilog's ILogger injected using Log.ForContext<T>, where T is the consumer

隐身守侯 提交于 2021-01-20 16:11:25
问题 Serilog allows creating a context-aware logger: Log.ForContext<T>() I would like to register Serilog with SimpleInjector in such a way that T is the type of the consumer, i.e. it is which class it is injected in to. e.g. public class Car { public Car(ILogger logger) <= would be injected using Log.ForContext<Car>() { } } I can see this has been done with AutoFac. And looking through the SimpleInjector documentation, there is a very promising overload of RegisterConditional() (with the Func

Serilog - Separate files for Information, exception using appsetting.json

生来就可爱ヽ(ⅴ<●) 提交于 2021-01-01 09:36:59
问题 I am writing all logs into one file(s) using rolling. But I want to separate them by Information , Warning and Exceptions rolling files. my current configuration is like this "Serilog": { "WriteTo": [ { "Name": "RollingFile", "Args": { "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}", "pathFormat": "logs\\log-{Hour}.log", "rollOnFileSizeLimit ": true, "retainedFileCountLimit ": null, "rollingInterval": "Hour", "fileSizeLimitBytes": 5000000 }

Serilog - Separate files for Information, exception using appsetting.json

ぃ、小莉子 提交于 2021-01-01 09:35:09
问题 I am writing all logs into one file(s) using rolling. But I want to separate them by Information , Warning and Exceptions rolling files. my current configuration is like this "Serilog": { "WriteTo": [ { "Name": "RollingFile", "Args": { "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}", "pathFormat": "logs\\log-{Hour}.log", "rollOnFileSizeLimit ": true, "retainedFileCountLimit ": null, "rollingInterval": "Hour", "fileSizeLimitBytes": 5000000 }

Serilog - Separate files for Information, exception using appsetting.json

浪子不回头ぞ 提交于 2021-01-01 09:34:54
问题 I am writing all logs into one file(s) using rolling. But I want to separate them by Information , Warning and Exceptions rolling files. my current configuration is like this "Serilog": { "WriteTo": [ { "Name": "RollingFile", "Args": { "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}", "pathFormat": "logs\\log-{Hour}.log", "rollOnFileSizeLimit ": true, "retainedFileCountLimit ": null, "rollingInterval": "Hour", "fileSizeLimitBytes": 5000000 }

Is it possible to change colors in serilog?

一世执手 提交于 2020-12-13 04:51:41
问题 I have just integrated Serilog in my dot net core project. It is working really well but I use a dark theme and some logs are really dificult to read. As an example: This is how I init Serilog: string environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); LoggerConfiguration loggerConfig = new LoggerConfiguration(); if (environment == "Production") loggerConfig.MinimumLevel.Information(); loggerConfig.MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Warning)

Is it possible to change colors in serilog?

孤人 提交于 2020-12-13 04:51:36
问题 I have just integrated Serilog in my dot net core project. It is working really well but I use a dark theme and some logs are really dificult to read. As an example: This is how I init Serilog: string environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); LoggerConfiguration loggerConfig = new LoggerConfiguration(); if (environment == "Production") loggerConfig.MinimumLevel.Information(); loggerConfig.MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Warning)

How to add 'request body' in serilog's output .net core?

╄→гoц情女王★ 提交于 2020-12-10 14:00:00
问题 I have a web API based on .net core 3.1. I'm using the SeriLog library as a logger. Here is my SeriLog Configuration. Serilog has been configured from 'appsettings.json'. I need to add 'request body' parameters to log's output if it exists. Is there any way to configure this. Also, I share my log output. 回答1: Please check this thread and this article. To log the request and response information (such as: request body), you could create a Middleware, and capture the request and response body

Serilog logging web-api methods, adding context properties inside middleware

不羁岁月 提交于 2020-12-03 07:37:16
问题 I've been struggling to log response body payload data with serilog, logging from middleware. I'm working on WEB API Core application, with swagger added to endpoints, and my goal is to log every endpoint call to a .json file with serilog (both request and response data). For GET requests, body of the response should be logged (added to serilog context as a property), and for POST requests, both body of request and response should be logged. I have created middleware and managed to properly

Serilog logging web-api methods, adding context properties inside middleware

好久不见. 提交于 2020-12-03 07:34:21
问题 I've been struggling to log response body payload data with serilog, logging from middleware. I'm working on WEB API Core application, with swagger added to endpoints, and my goal is to log every endpoint call to a .json file with serilog (both request and response data). For GET requests, body of the response should be logged (added to serilog context as a property), and for POST requests, both body of request and response should be logged. I have created middleware and managed to properly