serilog

Is it possible to get Timestamp in output template as DateTimeKind.Utc?

纵饮孤独 提交于 2019-12-01 15:08:22
问题 Currently when I use {Timestamp} in an outputTemplate it appears to have been generated by DateTime.Now and therefore being of DateTimeKind.Local flavor since, when I give it an "o" specifier it produces output similar to 2016-02-12T09:51:34.4477761-08:00 What I'd like to get instead for the above example is 2016-02-12T17:51:34.4477761Z , which would have been produced had the Timestamp been of DateTimeKind.Utc . Update It looks like it is actually DateTimeOffset that gets instantiated there

Add user to the log context when using Serilog and Asp.Net Core

旧城冷巷雨未停 提交于 2019-12-01 14:50:59
问题 I'm trying to use Serilog together with my ASP.Net Core 1.0 project. I just can't seem to get the current logged in user added to properties logged. Has anyone figure this out yet? I have tried this: using System.Threading.Tasks; using Serilog.Context; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using System.Security.Claims; using xxx.Models; namespace xxx.Utils { public class EnrichSerilogContextMiddleware { private readonly RequestDelegate _next; public

Is it possible to elegantly configure Serilog with if-statements?

谁都会走 提交于 2019-12-01 08:38:28
My Serilog configuration code looks like this: Log.Logger = new LoggerConfiguration() .Enrich.WithExceptionDetails() .Enrich.FromLogContext() .MinimumLevel.Warning() // .MinimumLevel.Override("Microsoft", LogEventLevel.Verbose) // .MinimumLevel.Override("System", LogEventLevel.Verbose) // .MinimumLevel.Override("Microsoft.AspNetCore.Authentication", LogEventLevel.Verbose) .WriteTo.Console( outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}", theme: AnsiConsoleTheme.Literate ) // .WriteTo.File() .CreateLogger(); I'd like to change

Specify directory for Serilog rolling file path

非 Y 不嫁゛ 提交于 2019-12-01 07:36:51
Consider this app.config appSetting entry: <add key="serilog:write-to:RollingFile.pathFormat" value="ServerServiceApp-{Date}.log" /> This is done at app startup: Log.Logger = new LoggerConfiguration() .ReadFrom.AppSettings() .Enrich.WithThreadId() .CreateLogger(); This is in a Windows service app. The log file ends up here: C:\Windows\SysWOW64 Clearly, we’d rather have the log file end up in the same directory that houses this service’s .exe (customers don’t want us writing stuff to SysWOW64). But how? We need the ReadFrom.AppSettings in there so that the customer can supply serilog settings

Is it possible to elegantly configure Serilog with if-statements?

白昼怎懂夜的黑 提交于 2019-12-01 07:07:38
问题 My Serilog configuration code looks like this: Log.Logger = new LoggerConfiguration() .Enrich.WithExceptionDetails() .Enrich.FromLogContext() .MinimumLevel.Warning() // .MinimumLevel.Override("Microsoft", LogEventLevel.Verbose) // .MinimumLevel.Override("System", LogEventLevel.Verbose) // .MinimumLevel.Override("Microsoft.AspNetCore.Authentication", LogEventLevel.Verbose) .WriteTo.Console( outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}

Specify directory for Serilog rolling file path

北战南征 提交于 2019-12-01 05:04:40
问题 Consider this app.config appSetting entry: <add key="serilog:write-to:RollingFile.pathFormat" value="ServerServiceApp-{Date}.log" /> This is done at app startup: Log.Logger = new LoggerConfiguration() .ReadFrom.AppSettings() .Enrich.WithThreadId() .CreateLogger(); This is in a Windows service app. The log file ends up here: C:\Windows\SysWOW64 Clearly, we’d rather have the log file end up in the same directory that houses this service’s .exe (customers don’t want us writing stuff to SysWOW64)

Configuring Serilog RollingFile with appsettings.json

青春壹個敷衍的年華 提交于 2019-11-30 11:34:19
I'm trying to configure Serilog for a .NET Core project. Here's what I have in my appsettings.json : "Serilog": { "MinimumLevel": "Verbose", "Enrich": ["FromLogContext", "WithMachineName", "WithProcessId", "WithThreadId"], "WriteTo": [ { "Name": "RollingFile", "Args": { "pathFormat": "C:/Logfiles/testapp/log-{Date}.json", "textFormatter": "JsonFormatter", "fileSizeLimitBytes": 2147483648, "retainedFileCountLimit": 5 } } ] } The problem I see is that JsonFormatter is not picked up, and instead I get entries using the default text formatter. I tried using "formatter": "JsonFormatter" , but got

Serilog MSSQL Sink doesn't write logs to database

寵の児 提交于 2019-11-29 12:27:59
I have created a .Net class library (4.6.2) and created serilog implementation which is called by other interfaces such as console app. Now when I use File sink type, the logs are getting written to the files but with MSSQL sink, its not doing so. The log tables are getting created with column options as provided with autoCreateTable options ILogger logger = new LoggerConfiguration() .WriteTo.MSSqlServer(connectionString, tableName, autoCreateSqlTable: autoCreateSqlTable, restrictedToMinimumLevel: LogEventLevel.Verbose, columnOptions: GetSQLSinkColumnOptions(), batchPostingLimit:

Serilog.Sinks.MSSqlServer not filling custom columns

╄→尐↘猪︶ㄣ 提交于 2019-11-29 07:14:57
I've looked around, but I could not find a working solution, and since all examples look alike I assume it must be me overlooking something obvious. Also note this is my first real project using.NET Core and Serilog. The Problem I am trying to log (using serilog) some custom properties into their own columns in the database as defined in appsettings.json and added via middleware on the pipeline. But the values remain NULL, even though the same items are correctly filled in the properties XML column. So I have the expected new properties for authenticated users: <properties> <property key=

Multiple filters for one logger with Serilog

核能气质少年 提交于 2019-11-28 23:49:07
I am trying to setup Serilog with my ASP.NET Core application. I'd like to have one log file for all controllers, one for all services, one for the rest and ideally one which contains everything. Every controller is inheriting BaseController and every service BaseService . The controller and the service I am calling are writing a trace log event. The logger and the service are retrieved via dependy injection. The service looks like the controller (regarding the logger). public class UsersController: BaseController { private UserService service { get; } public UsersController(ILogger