serilog

How do I pass a dependency to a Serilog Enricher?

你离开我真会死。 提交于 2019-12-23 08:49:58
问题 I'm using Serilog in my application for logging. When I'm configuring the logger, I have code like this: var log = new LoggerConfiguration() .Enrich.With<MySerilogEnricher>() .ReadAppSettings() .CreateLogger(); I want to inject some dependencies into my MySerilogEnricher class, but when I try, I get this compiler error: error CS0310: 'SerilogEnricher' must be a non-abstract type with a public parameterless constructor in order to use it as parameter 'TEnricher' in the generic type or method

With SerilogWeb.Owin discontinued, is there an “official” integration?

ⅰ亾dé卋堺 提交于 2019-12-23 07:29:09
问题 I came across the discontinuation notice of the SerilogWeb.Owin package, and in reading the GitHub issue there was discussion about "redirecting folks somewhere" given the ~5K+ downloads of the package. But I haven't been able to figure out where I'm being redirected to! So where should I be looking for a "Serilog-blessed" integration for using Serilog with an (OWIN) self-hosted Web API? 回答1: The package boils down to the following, which I derived from the issues in [the repo](https://github

No errors logged for Serilog SQL server sink logging

不想你离开。 提交于 2019-12-23 04:55:19
问题 I have configured Serilog SQL server sink for my ASP.Net Core 2.2 web application based on the documentation. Neither the Logs table get created nor are any errors logged. What am I missing? AppSettings.Development.json: { "ConnectionStrings": { "SQLServerConnectionString": "<ActualDataBaseConnectionString>" }, "Serilog": { "Using": [ "Serilog.Sinks.MSSqlServer" ], "MinimumLevel": "Information", "WriteTo": [ { "Name": "MSSqlServer", "Args": { "connectionString": "SQLServerConnectionString",

Serilog not working from configuration in asp.net core 2.2 API

狂风中的少年 提交于 2019-12-22 04:37:25
问题 public class Program { public static void Main(string[] args) { CreateWebHostBuilder(args).Build().Run(); } public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .UseSerilog((ctx, config) => { config.ReadFrom.Configuration(ctx.Configuration); }) .UseStartup<Startup>(); } public class Startup { public IContainer Container { get; private set; } public Startup(IConfiguration configuration) { Log.Warning("test"); Configuration = configuration; } }

Serilog RollingFile

跟風遠走 提交于 2019-12-22 03:16:27
问题 I am trying to use WriteTo.RollingFile with Serilog as the following: var log = new LoggerConfiguration().WriteTo.RollingFile( @"F:\logs\log-{Date}.txt", LogEventLevel.Debug).CreateLogger(); log.Information("this is a log test"); My understanding is that the log file will be created and named based on the date, and also it will write to a new file everyday, however I am getting a new log file for each log entry during the same day! How to configure Serilog to write to a new file every day so

How to output event source Class Name in serilog RollingFile outputTemplate?

孤者浪人 提交于 2019-12-22 02:22:21
问题 The RollingFile.outputTemplate that I am using for my sink in <appSettings> configuration is as below: <add key="serilog:write-to:RollingFile.outputTemplate" value="{Timestamp:HH:mm:ss} [{Level}] {Message}{NewLine}{Exception}" /> The output log I am getting as: 19:55:10 [Information] Application_Start... However, I want to also output the Class Name (source) from where the Log was generated, like - 19:55:10 [Information] [Global.asax.cs] Application_Start... What should I add to the "value"?

Add Username into Serilog

青春壹個敷衍的年華 提交于 2019-12-21 12:00:55
问题 I have this Serilog configuration in program.cs public class Program { public static IConfiguration Configuration { get; } = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", optional: true) .Build(); public static void Main(string[] args) { Log.Logger = new LoggerConfiguration()

Package restore failed. Rolling back package changes - Serilog.AspNetCore

不羁的心 提交于 2019-12-21 09:27:28
问题 I have an asp.net Core project and I'm trying to add a logger to it. I choose SeriLog which I used in other projects. But when I'm trying to add the " Serilog.AspNetCore " package version 2.0.0 I'm getting" Package restore failed. Rolling back package changes for 'BackEnd'. My csproj contain the following settings: <PropertyGroup> <TargetFramework>netcoreapp2.0</TargetFramework> <DockerComposeProjectPath>..\..\docker-compose.dcproj</DockerComposeProjectPath> <AssemblyName>BackEnd<

Add custom properties to Serilog

寵の児 提交于 2019-12-21 03:45:09
问题 I'm using Serilog with an MS SQL Server sink in my application. Let's assume I have defined the following class ... public class Person { public string FirstName { get; set; } public string LastName { get; set; } public DateTime BirthDate { get; set; } // ... more properties } ... and created an instance: var person = new Person { FirstName = "John", LastName = "Doe", BirthDate = DateTime.UtcNow.AddYears(-25) }; I have placed the following log call in my code: Log.Information("New user:

Pattern to use Serilog (pass ILogger vs using static Serilog.Log)

╄→尐↘猪︶ㄣ 提交于 2019-12-20 10:42:12
问题 Background In a new project where Serilog was chosen as the logger I automatically started passing around ILogger interface. The code accesses Log.Logger once and from then the classes that desire logging accept ILogger via constructor injection. I was challenged on this practice and the advice was to use the static methods on the Log class, e.g. Serilog.Log.Debug(...) . The argument is that there is a set; on Log.Logger so mocking is easy. Looking at the api I can see that one of the