serilog

Inject a dependency in a SeriLog enricher with autofac

£可爱£侵袭症+ 提交于 2021-02-20 19:05:38
问题 I want to create a Serilog Enricher injecting some data from a dependency. How can autofac inject my dependency into an enricher? This is my container setup: builder.Register((c, p) => { return new LoggerConfiguration() .Enrich.FromLogContext() .Enrich.With<MyEnricherWhichCanAddMoreDataFromADependency>() // ... .CreateLogger(); }).As<ILogger>(); While the enricher would look something like public class MyEnricherWhichCanAddMoreDataFromADependency : ILogEventEnricher { public

Inject a dependency in a SeriLog enricher with autofac

。_饼干妹妹 提交于 2021-02-20 19:05:22
问题 I want to create a Serilog Enricher injecting some data from a dependency. How can autofac inject my dependency into an enricher? This is my container setup: builder.Register((c, p) => { return new LoggerConfiguration() .Enrich.FromLogContext() .Enrich.With<MyEnricherWhichCanAddMoreDataFromADependency>() // ... .CreateLogger(); }).As<ILogger>(); While the enricher would look something like public class MyEnricherWhichCanAddMoreDataFromADependency : ILogEventEnricher { public

Unit test serilog configuration

烈酒焚心 提交于 2021-02-16 18:07:57
问题 I have a piece of code for setting up serilog based on some custom configuration combined with hosting environment. E.g. the application writes to one sink in development and another sink in production. I'm trying to figure out how to write tests for this piece of code. Basically, I want to write a test that checks that a sink only is added if the environment name is set to a given value, and that the sink configuration, like log file path, respects the custom configuration that I provide.

Unit test serilog configuration

半腔热情 提交于 2021-02-16 18:06:51
问题 I have a piece of code for setting up serilog based on some custom configuration combined with hosting environment. E.g. the application writes to one sink in development and another sink in production. I'm trying to figure out how to write tests for this piece of code. Basically, I want to write a test that checks that a sink only is added if the environment name is set to a given value, and that the sink configuration, like log file path, respects the custom configuration that I provide.

Serilog - AppSettings MinLevel not working

爱⌒轻易说出口 提交于 2021-02-10 13:28:13
问题 I am trying to wire up my sinks and it seems for my rolling file sink my debug messages are not being logged (only info and above). Is my configuration wrong? <!-- Serilog Configuration --> <add key="serilog:using:Email" value="Serilog.Sinks.Email" /> <!-- Configure Serilog Email Sink --> <add key="serilog:write-to:Email" /> <add key="serilog:write-to:Email.mailServer" value="***" /> <add key="serilog:write-to:Email.toEmail" value="***" /> <add key="serilog:write-to:Email.fromEmail" value="**

Serilog : how to NOT log some requests (or to log with different levels)

风格不统一 提交于 2021-02-10 13:10:40
问题 At the moment, I enable Serilog to log all the HTTP requests made to my server (see Program.cs and logging.json below). However, Openshift is calling /ready and /live and I do not want to log these requests {"@t":"2020-12-17T15:02:08.7321442Z","@m":"HTTP \"GET\" \"/ready\" responded 200 in 41.3777 ms","@i":"62d0885c","RequestMethod":"GET","RequestPath":"/ready","StatusCode":200,"Elapsed":41.3777,"SourceContext":"Serilog.AspNetCore.RequestLoggingMiddleware","RequestId":"0HM52JISL6NBA:00000001"

Serilog : how to NOT log some requests (or to log with different levels)

有些话、适合烂在心里 提交于 2021-02-10 13:03:46
问题 At the moment, I enable Serilog to log all the HTTP requests made to my server (see Program.cs and logging.json below). However, Openshift is calling /ready and /live and I do not want to log these requests {"@t":"2020-12-17T15:02:08.7321442Z","@m":"HTTP \"GET\" \"/ready\" responded 200 in 41.3777 ms","@i":"62d0885c","RequestMethod":"GET","RequestPath":"/ready","StatusCode":200,"Elapsed":41.3777,"SourceContext":"Serilog.AspNetCore.RequestLoggingMiddleware","RequestId":"0HM52JISL6NBA:00000001"

log4net method GetLogger() Equivalent in Serilog

隐身守侯 提交于 2021-02-10 10:57:45
问题 Brief Backround We are replacing in our project the log4net to Serilog . In many of our classes we are using the method LogManager.GetLogger of log4net when giving as a parameter the class name using MethodBase.GetCurrentMethod().DeclaringType , so we could know in which class the log was written. My Question Is Is there any method which is equivalent in Serilog which can give me the logger? I know that there is the option of ForContext() which you can specify the class you're in, but I still

log4net method GetLogger() Equivalent in Serilog

匆匆过客 提交于 2021-02-10 10:57:26
问题 Brief Backround We are replacing in our project the log4net to Serilog . In many of our classes we are using the method LogManager.GetLogger of log4net when giving as a parameter the class name using MethodBase.GetCurrentMethod().DeclaringType , so we could know in which class the log was written. My Question Is Is there any method which is equivalent in Serilog which can give me the logger? I know that there is the option of ForContext() which you can specify the class you're in, but I still

How to setup serilog SEQ for .NET Core 3.0 Worker Service

限于喜欢 提交于 2021-02-10 05:12:52
问题 Logging is working but it is not posting to my local seq, I tried adding serilog and also useSerilog but it does not logging into my local service: related question .csproj <ItemGroup> <PackageReference Include="Microsoft.AspNet.Mvc" Version="5.2.7" /> <PackageReference Include="Microsoft.Extensions.Hosting" Version="3.0.0" /> <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.0.1" /> <PackageReference Include="Serilog" Version="2.8.0" /> <PackageReference Include=