serilog

Persisting EventType with Serilog

纵饮孤独 提交于 2019-12-11 06:05:43
问题 I'm having trouble getting the EventType feature working in Serilog, as blogged about here. I am using the following Nuget packages: Serilog 2.8 Serilog.Settings.Configuration 3.0.1 Serilog.Sinks.File 4.0.0 Serilog.Sinks.MSSqlServer 5.1.2 First up, I created an EventTypeEnricher : public class EventTypeEnricher : ILogEventEnricher { public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) { var crypto = new SimpleCrypto.PBKDF2(); var hash = crypto.Compute(logEvent

Clear a log file at runtime:Used by another process error

对着背影说爱祢 提交于 2019-12-11 05:14:31
问题 I am using serilog framework in my application. In my application when the log file size reaches 2MB, im creating a backup of log file by renaming the existing file from file.log to file.log.bak and creating a new file.log. At runtime i was facing issue reading the log file, "the process logfile is used by another process" error was shown. so i used below code to read the content of serilog file. Stream stream = File.Open (_filepath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

Serilog ForContext not working as expected

喜欢而已 提交于 2019-12-11 04:06:48
问题 I am using serilog & SEQ with Autofac (DI) in my project (MVC/ web api etc). Although it's working fine but not sure it's the right way. I have few questions. please help Q1) How can I make LoggerConfiguration is manage via Web.config (appsetting) such as Verbose/Debug etc. Log.Logger = new LoggerConfiguration() .MinimumLevel.Verbose() .Enrich.FromLogContext() .WriteTo.Seq(serilogUrl) .CreateLogger(); Q2) With Everymessage I would like to write userid. I have used push propery with out "using

Serilog Additional Properties

房东的猫 提交于 2019-12-11 00:58:23
问题 I work working with Serilog and logging events to SQL Server (using the Serilog, Serilog.Framework.Logging and Serilog.Sinks.MSSqlServer libraries). As part of an MVC6 application, when I log events and set the option to include properties, I see some additional properties in the XML column. If I issue something like the following statement: Log.Information("{Property1}", "Value1"); I see something like the following in the Properties column: <properties> <property key="Property1">Value1<

Trying to Configure Serilog Email sink with appsettings.json to work with Gmail

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 00:11:23
问题 In in a POC I got the Smtp client to send emails through Gmail, so I know my information regarding connecting to Gmail's SMTP server is correct. I am now trying to configure Serilog through appsettings.json to send my log entries through Gmail. I need to be able to configure it different for different environments. I currently have it set to Verbose so that I get anything...it won't be that way later. I am not getting anything but my file log entry. I had this working with a local network

How to create a Custom text formatter for Cloudwatch?

蓝咒 提交于 2019-12-10 19:36:12
问题 I don't understand how to create a custom text formatter for Amazon Cloudwatch as mentioned: var formatter = new MyCustomTextFormatter(); I am trying to write Serilog logs to Amazon CloudWatch instead of the local hard disk. To do that I am following this repo: https://github.com/Cimpress-MCP/serilog-sinks-awscloudwatch private readonly ITextFormatter textFormatter; public ILoggerFactory ConfigureLogger() { LoggerFactory factory = new LoggerFactory(); var logGroupName = "myLoggrouName"; var

How to set Steeltoe Dynamic Logging works with 3rd party loggers as Serilog?

我怕爱的太早我们不能终老 提交于 2019-12-10 19:00:49
问题 I have ASP.NET Core 2.1 app in Pivotal Cloud Foundry where we want to be able to configure logging levels on fly. As logger provider we are using Serilog. Is it possible that Steeltoe Dynamic Logging works properly with 3rd party loggers and how? Here is what I tried: In Program.cs: public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .UseCloudFoundryHosting() .ConfigureLogging((builderContext, loggingBuilder) => { loggingBuilder

How can I add a named property that is not part of the message template?

会有一股神秘感。 提交于 2019-12-10 17:09:32
问题 In some cases, I would like to add contextual information to a message (for instance currently authenticated user), without having to include it in the message template . I would like to accomplish this : logger.Information("Doing stuff {Foo} with the thing {Bar}. {User}", foo, bar, user) but without the {User} in the template. I already know about LogContext but that seems overkill when adding contextual information to just one event. I also know I can use the low-level API logger.Write

User doesn't seem authenticated in the pipline inside`Use` in dotnetcore 2.0

人走茶凉 提交于 2019-12-10 17:08:53
问题 I am trying to provide an ActiveUser property to Serilog. Unfortunately I cannot seem to find the correct spot to check for the current user. In the below code httpContext.User.Identity.IsAuthenticated is always false? But only when logging in with the bearer token The bearer token login is working correctly insofar as the user is authenticated to the controller methods, and the user needs to belong to the correct roles in order to be authenticated. Though the user name is not correctly set -

Serilog - Configuring Multiple Sinks in AppSettings

陌路散爱 提交于 2019-12-10 16:59:46
问题 I am trying to wire-up serilog using the app settings package and when I run my program Serlog is complaining it cannot find the RollingFile assembly. I did not have this problem using a single sink but multiple it giving me fits: <!-- Serilog Configuration --> <add key="serilog:using:Email" value="Serilog.Sinks.Email" /> <add key="serilog:using:RollingFile" value="Serilog.Sinks.RollingFile" /> <!-- Configure Serilog Email Sink --> <add key="serilog:write-to:Email"/> <add key="serilog:write