serilog

Avoid logging twice using netcore2.0 on AWS Lambda with Serilog

大城市里の小女人 提交于 2019-12-24 06:25:22
问题 After upgrading my netcore project to 2.0, i see double logs when my application is running on AWS Lambda, which utilizes the Serilog framework. Please see my setup below: public void ConfigureServices(IServiceCollection services) { ... // Setup logging Serilog.Debugging.SelfLog.Enable(Console.Error); var logger = new LoggerConfiguration() .MinimumLevel.Debug() .Enrich.FromLogContext(); if (GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "").Equals("local")) logger.WriteTo.Console(); else

Using SeriLog through a wrapper class

不打扰是莪最后的温柔 提交于 2019-12-24 05:35:50
问题 I have a solution with multiple .EXEs, WCF services, Windows Services, etc... I want to use SeriLog for logging in all of these but I don't want these projects to add SeriLog directly. I want them to depend upon a Frameword dll that has various things like email, configuration, etc... To that end I want to create a wrapper class in this Framework dll. All my projects can then just refer to this wrapper class (part of a dll they are already referring to). So, I want something like: public

Can I log to separate files using Serilog?

爷,独闯天下 提交于 2019-12-24 05:22:08
问题 My ASP.NET Core 2.1 app logs to a Serilog file sink, all the "usual stuff" - i.e. app related stuff such as debug, monitoring, performance, etc. However we also need to log other data to a separate file. Not app related, but customer related - the kind of stuff that should go into a database. However for legacy reasons, there is no database on this system and so that data needs to be saved to a file instead. Obviously this can't be written to the same log file. I could just write to a

How to specify JsonFormatter in Web.config for SeriLog?

ⅰ亾dé卋堺 提交于 2019-12-24 04:49:09
问题 I am trying to figure out how to specify JsonFormatter in web.config for SeriLog, I am also using rolling file sink and that is specified in the web.config as well. 回答1: There isn't currently any support for specifying custom text formatters in XML with Serilog. Using code to perform this configuration, perhaps based on reading an app setting, is your best bet today. 来源: https://stackoverflow.com/questions/32053859/how-to-specify-jsonformatter-in-web-config-for-serilog

Serilog with Asp.net Web Api not using enricher

北慕城南 提交于 2019-12-24 01:54:47
问题 I have a Microsoft Asp.Net Web Api project, in which I am attempting to setup serilog logging. I have installed the Nuget packages for Serilog, Serilog.Sinks.File, SerilogWeb.Classic, and SerilogWeb.Classic.WebApi. Note, that I am NOT able to use .Net Core. My problem is that I am attempting to use the enrichers from the SerilogWeb.CLassic.WebApi package, but they aren't changing my output. I am sure that what I am doing is a simple mistake, but I cannot find any examples of others using this

Trouble converting Serilog Configuration code line to json configuration

蓝咒 提交于 2019-12-24 00:37:16
问题 I found a post where the blogger explained how to filter by LogEvent level to a separate file for Serilog configuration. I am doing all my Serilog configuration in my appsettings.json. How would this look in json configuration, I can't seem to figure how to json the lambda expression.... Logger = new LoggerConfiguration() .MinimumLevel.Information() .WriteTo.Logger(l => l.Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Warning).WriteTo.RollingFile(@"Logs\Warning-{Date}.log")) I am using

Only first logging shows unless forcefully disposing

◇◆丶佛笑我妖孽 提交于 2019-12-23 18:22:38
问题 I'm using vs 2017, writing a netcoreapp2.0 library, and testing it with a UnitTest project (XUnit and NUnit give same results). I've noticed that unless I'm forcefully Disposing of my Serilog logger, only the first line will end up in Seq . Here are my 2 classes. The library one: public class Class1 { public static Logger _log; public Class1(Logger log) { _log = log; _log.Verbose("Class 1 constructor fineshed"); } public void LogMessage(string s) { _log.Debug("Got message: {Message}", s); } }

Serilog: difference between {..} and {@..}

最后都变了- 提交于 2019-12-23 16:47:30
问题 Given this code: var d1 = new { x = 5, y = 88 }; Log.Logger.Information("{d1}", d1); Log.Logger.Information("{@d1}", d1); How will the object in d1 be logged differently in the two Log.Logger.Information(...) lines? In other words, what is the effect of adding the @ in between the { } ? I read https://github.com/serilog/serilog/wiki/Structured-Data under the heading "Preserving Object Structure", but that didn't make sense to me. 回答1: {d1} converts unrecognized types like the anonymous one

Serilog logs collected by Fluentbit to Elasticsearch in kubernetes doesnt get Json-parsed correctly

有些话、适合烂在心里 提交于 2019-12-23 12:44:13
问题 Using the EFK Stack on Kubernetes (Minikube). Have an asp.net core app using Serilog to write to console as Json. Logs DO ship to Elasticsearch, but they arrive unparsed strings , into the "log" field, this is the problem. This is the console output: { "@timestamp": "2019-03-22T22:08:24.6499272+01:00", "level": "Fatal", "messageTemplate": "Text: {Message}", "message": "Text: \"aaaa\"", "exception": { "Depth": 0, "ClassName": "", "Message": "Boom!", "Source": null, "StackTraceString": null,

How do I pass a dependency to a Serilog Enricher?

与世无争的帅哥 提交于 2019-12-23 08:50:03
问题 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