Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Apr 08 22:46

    nblumhardt on dev

    Update appveyor.yml (compare)

  • Apr 08 22:40

    nblumhardt on dev

    Another attempt at NuGet publis… (compare)

  • Apr 05 14:59

    skomis-mm on dev

    Update README.md Fix typo in R… Merge pull request #46 from Mar… (compare)

  • Mar 29 03:53

    serilog-build on v4.1.0

    (compare)

  • Mar 29 03:18

    serilog-build on v225

    (compare)

  • Mar 29 03:18

    nblumhardt on dev

    Dev version bump [skip ci] (compare)

  • Mar 29 03:17

    nblumhardt on main

    Dev version bump [skip ci] Drop Microsoft.AspNetCore.Http.… I think this comment is correct and 8 more (compare)

  • Mar 29 03:11

    nblumhardt on dev

    Minor version bump - dependenci… (compare)

  • Mar 29 03:10

    nblumhardt on sdk-update

    (compare)

  • Mar 28 21:55

    serilog-build on v2.0.0

    (compare)

  • Mar 27 07:38

    serilog-build on v34

    (compare)

  • Mar 27 07:37

    nblumhardt on dev

    Dev version bump [skip ci] (compare)

  • Mar 27 07:37

    nblumhardt on main

    Dev version bump [skip ci] New template tokenizer WIP New template parser and 15 more (compare)

  • Mar 26 23:12

    nblumhardt on dev

    Publishing key update (compare)

  • Mar 26 23:05

    nblumhardt on dev

    Update Microsoft.Azure.EventHub… task: remove 451 support, rev v… bug: Fix build failure for 461 and 2 more (compare)

  • Mar 26 23:03

    nblumhardt on dev

    Bump SDK version Merge pull request #242 from se… (compare)

  • Mar 26 23:03

    nblumhardt on dev

    Update README to show how envir… (compare)

  • Mar 26 23:00

    nblumhardt on sdk-update

    Bump SDK version (compare)

  • Mar 22 10:50

    nblumhardt on dev

    Optional argument handling and … Merge pull request #31 from nbl… (compare)

  • Mar 21 06:25

    nblumhardt on dev

    New template tokenizer WIP New template parser Basics of #if/else if/else/end … and 11 more (compare)

pvnmurthy
@pvnmurthy
Hi, I have a multi-threaded application and I want to create a new rolling log file(file name should contain thread name and thread ID) for each thread in the app. I prefer to use Serilog configuration file for doing this. Please help me how I can achieving this functionality. Please let me know if you need more details.
Daniel Hughes
@trampster
Is there a way to set the SourceContext manually at logging time
At the moment it gets set up front using ForContext, But I need each log message to have a different SourceContext (not tied to the .net class name etc) can this be done without creating a new logger using ForContext for each log message
Daniel Hughes
@trampster
(the log messages actually come from a native lib and already have a name which relates to the native class, I want to use that name as the SourceContext) but don't know the name until I receive each message.
Ruben Bartelink
@bartelink
@trampster any given logger can have its SourceContext altered by calling .ForContext<T>() (or another overload) and using the object that fluent syntax yields to do the logging. i.e. var log = Log.ForContext<A>(); log.ForContext<B>().Information("Test") will have SourceContext=Test
@pvnmurthy as you've probably worked out by now, stackoverflow.com is going to be much more responsive - people who come here and answer anything also see the serilog tag there. (I have never used text config or wanted a thread name in my log but there shoiuld be a plugin somewhere to Enrich.WithThreadContext if you google)
@thavasnippets StackOverflow is the best place to get an answer.
Ruben Bartelink
@bartelink
@OgnjenAnari best place for that would be to look in issues or doc on that sink's github (don't ask questions on a sink repo though) or ask on stackoverflow
@bartzy you can implement ILogSink and then .WriteTo.Sink(new MySink()) - best to start from an example; I bet searching up MessageBox Sink Serilog will yield something, or look at a simple sink like one that writes to Trace or Debug to get started
advapiIT
@advapiIT
Hello everybody... I need help if possible... I need to specify via appsetting.config that some specific events must be sent to Eventviewer only...
I mean I've this
        protected override void OnShutdown()
        {
            base.OnShutdown();
            log.Information("Shutdown");
         //   EventLog.WriteEntry(DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss:fff") + " " + "Shutdown");
        }
this must only be sent to the EventViewer, is possible via appsettings? I-ve installed the Filter extension but I don't know how to setup things correcly
C. Augusto Proiete
@augustoproiete
@advapiIT You'll get more eyeballs on your question here: https://stackoverflow.com/questions/tagged/serilog
Jens Willmer
@jwillmer
Hi, I try to use the email sink together with the appsetings.json in my ASP.NET Core app. However I don't get any exceptions or sent email. How can I debug if the configuration is working?
Jens Willmer
@jwillmer
O.K., found the solution. Be patient and wait :( serilog/serilog-sinks-email#61
Grimur Jonsson
@grimurjonsson
Greetings, I'm looking for a way to configure the Serilog.Sinks.Fluentd to log milliseconds. I can do if for Console by using the outputTemplate property, but that's not available in the Fluentd one as far as I can tell. Anyone have a solution for this?
Nicholas Blumhardt
@nblumhardt
A long-overdue PR: dotnet/sdk#15865
@jwillmer unfortunately we need more maintainer time on that sink :(
Skeferstat
@Skeferstat
Hi, I write my logs to console and file. But I have a litte animation (spinning circcle) and this animation should only be visible on the console. How I can do this with serilog? Thanks!
Nicholas Blumhardt
@nblumhardt
@Skeferstat my first instinct is to use Console.WriteLine() directly for this kind of output - it's not really "logging" in this case, but if you want to pipe it through the sink you can filter it out from the file using WriteTo.Conditional() for the file, where the condition would need some way to exclude the animation events (perhaps according to their SourceContext property)
Skeferstat
@Skeferstat
@nblumhardt Thansk!
George Kinsman
@gkinsman
Hi there, hope you're well :). Just having some conversations around MSEL vs Serilog at work, and I was wondering if there are any downsides to using Serilog.AspNetCore? If I understand, it wholly replaces the pipeline so that the existing ILoggerProvider infra doesn't contribute, but are there any other issues with it?
George Kinsman
@gkinsman
The only real thing I can find is that Serilog won't capture ambient scope additions, which is expected.
Vignesh-coder-coder
@Vignesh-coder-coder
Hi, I need to write log into AmazonS3 using Serilog, is there any way to sink S3.
2 replies
Stefan Zetterberg
@StefanZetterberg

Hi
I'm using Serilog and am trying to use MariaDB sink. I have MySqlConnector package version 1.2.1 installed but get the following error from Selflog during startup:
Could not load type 'MySql.Data.MySqlClient.MySqlConnection' from assembly 'MySqlConnector, Version=1.0.0.0, Culture=natural, PublicKeyToken=d33d3e53aa5f8c92'
at Serilog.Sinks.MariaDB.SqlTableCreator.CreateTable()

What am I doing wrong? Can anyone help me? Serilog looks very very good so i very much would like to use it.

SAILAKSHMIBHATTARAM
@SAILAKSHMIBHATTARAM
Hi
I'm using serilog and trying writeto.File(), reading configuration from appsettings.json file.. But the problem here is I need two log files based on the application name, since I will be using the serilog project as a utility based on the Assembly from which the application is running I should create respective files. I tried adding filters in json file for writeto tag there is no luck. Please help me in this.
{
"Serilog": {
"Using": [ "Serilog.Sinks.File" ],
"FilterSwitches": {
"$filterSwitch": "Application = 'GE.Opc.Ua.Client.Adaptor.Service'"},
"MinimumLevel": {
"Default": "Debug"
},
"WriteTo": [
{
"Name": "Logger",
"Args": {
"configureLogger": {
"Filter": [
{
"Name": "ByIncludingOnly",
"Args": {
"inclusionPredicate": {
"logEvent": {
"Properties": {
"Application": "GE.Opc.Ua.Client.Adaptor.Service"
}
}
}
}
}
],
"Enrich": [
"FromLogContext",
"WithMachineName",
{
"Name": "When",
"Args": {
"expression": "Application = 'GE.Opc.Ua.Client.Adaptor.Service'"
},
"configureEnricher": [ "WithMachineName", "FromLogContext", "WithThreadId" ]
}
],
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "%TEMP%/Logs/AdaptorConfig2.txt",
"outputTemplate": "[{Timestamp:HH:mm:ss}] {SourceContext} [{Level}] {Message}{NewLine}{Exception}"
}
}
]
}
}
},
{
"Name": "Logger",
"Args": {
"configureLogger": {
"Filter": [
{
"Name": "ByIncludingOnly",
"Args": {
"inclusionPredicate": {
"logEvent": {
"Properties": {
"Application": "GE.Opc.Ua.Client.TestApp.Service"
}
}
}
}
}
],
"Enrich": [
"FromLogContext",
"WithMachineName",
{
"Name": "When",
"Args": {
"expression": "Application = 'GE.Opc.Ua.Client.TestApp.Service'"
},
"configureEnricher": [ "WithMachineName", "FromLogContext", "WithThreadId" ]
}
],
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "%TEMP%/Logs/TestAppConfig2.txt",
"outputTemplate": "[{Timestamp:HH:mm:ss}] {SourceContext} [{Level}] {Message}{NewLine}{Exception}"
}
}
]
}
}
}
]
}
}
2 replies
Ky.
@RedactedProfile
Im trying to add a generic property to the root payload. At least in the Elastic Sink, Enrich adds properties into the "Fields" object, where I need it added to the root object
How does one go about doing that?
Elton Alves
@tiiaaooo_twitter

Hello, I need to override de format that serilog output TimeStamp format.

"@t": "2021-03-10T13:29:34.2189486Z", I need to converto to ISO 8601 => 2020-01-16T19:00:45-06:00

Anyone could help me please?

Sebastian Loncar
@arakis
Arthri
@Arthri
What format does LoggerConfiguration.ReadFrom.KeyValuePairs() use?
is it like AppSettings(https://github.com/serilog/serilog/wiki/AppSettings)?
thanks in advance!
RENO-911
@RENO-911
image.png
Has anyone here ever encountered a bunch of whitespaces in their loggingbuffer (http sink)?
gilgamesh
@nickSdl

Hi,

Can you please advise, if there is a good way to change log file parameters, like size and retainedfilecount in runtime without re-creating the logger?
Something similar to the MinimumLevel.ControlledBy(LoggingLevelSwitch)?

I've posted question on stackoverflow - https://stackoverflow.com/questions/66598428/is-there-an-option-in-serilog-to-change-log-file-parameters-in-runtime-the-same

If it's not possible/feasible, can you elaborate as well?

Thanks,
Nick

George Kosmidis
@georgekosmidis
Hey all! Very happy to e-meet you!
I have a question - not sure where to ask:
I use Serilog to push logs to Elasticsearch and it seems there are two "kinds" of logs. Request logs produced by "UseSerilogRequestLogging(...)" and logs from the developers (when the explicitly want to log something). Is there a way to use different indexes (IndexFormat = "...") for each case?
Thank you!
Nicholas Blumhardt
@nblumhardt
Hi George 👋 - good to meet you, too. Unless someone with Elastic experience can jump in, here, I think the wider audience on Stack Overflow will be your best bet for finding this info
Kasper Toft Andersen
@toftware
@georgekosmidis Try setting up another Serilog instance with the ElasticSearch sink settings you want, and pass it to https://github.com/serilog/serilog-aspnetcore/blob/dev/src/Serilog.AspNetCore/AspNetCore/RequestLoggingOptions.cs#L69
Androshchuk Vladyslav
@AndersonDev
Hi! Is it ok, to create 1 logger per class? I can see allocation a new logger class on each FromContext. It is not possible to add some sort of caching?
GANESHKUMAR
@rgkjobmail_twitter
Hi, I am trying to log the exceptions in aws s3 bucket by using .net core 3.1 web api. I am using serilog.sinks.amazons3 package for configure the logger in program.cs Code is working fine. But log file is not generated in s3. Any one can help me for this?
image.png
Brandon Tull
@btull89
Is there anyway to set the jsonformatter "renderMessage=true" through serilog configuration appsettings.json? I'm not interested in using the compact logger.
Rune Antonsen
@ruant
Anyone have quick tutorial/howto about using Serilog with WCF? To log Request and Responses
loneshark99
@loneshark99
Hi Guys, I am trying to understand how the LogContext works, specifically if I call a method in the LogContext using block, how does the logging statement inside the method knows to use the PushedProperty. Can someone give some hint?
image.png
Nicholas Blumhardt
@nblumhardt
@loneshark99 AsyncLocal<T> :+1:
Endy Tjahjono
@ndc
Hi all, is there any info on storage space consumption of serilog? I know it depends on usage, but what is the best way to estimate? Let's say I use SQL Server sink saving the parameters as XML.
Nicholas Blumhardt
@nblumhardt
@ndc measuring is the only way - the fixed overhead per event is small, the bulk of the stored data is what's generated by your application. It's no different from estimating how much space you'll need to store a photo - could be 300 KB, could be 16 MB, could be more or less - depends entirely on the data. HTH!
salvatore
@erotavlas
Hello, What is the best way to handle logging in the following scenario - I have a WPF desktop application which serves as the user interface around several different referenced projects (class library projects). I want to provide logging in the main WPF application but also I need to log messages in the referenced projects. I noticed that if I initialize the configuration to write to a file sink in the main WPF app, that I can simply use the static instance of Log in the referenced projects as long as I installed the nuget package of SeriLog in them - and it points to file sink I set in the WPF app. However my concern about leaving it this way is that the referenced project can be used in other applications like a console app, then the main configuration defined in the WPF app is lost - the code stays the same but Log.Write doesn't write anywhere. I'm just not sure what the best practice here is. Should I use dependancy injection to pass the ILogger between projects? Should I move the initialization of the LoggerConfiguration to one of the lower level libraries? Thanks for any advice.
Ruben Bartelink
@bartelink

@erotavlas best to ask on stackoverflow for max traffic - anyone that reads and answers here watches the serilog tag there too, plus a few million others ;) I'd suggest you still do that (it may even be answered; the closest thing I've seen I can think of is this answer [by me] https://stackoverflow.com/questions/50712720/pattern-to-use-serilog-pass-ilogger-vs-using-static-serilog-log)

In general, in a library, you can go one of two ways: require an ILogger to be passed, or assume the static one is initialized. For a truly generic library, you'll want to go the first way. However if you're coupling strongly to Serilog system wide anyway, it won't buy you much (in some testing scenarios, it can be valuable to be able to hook log outputs). That leaves what way you want to wire it between the host app and the library...

In general, you want the host startup to rig things; it's responsible for providing the environment that app code and lib can assume is present.

Using a container/DI to propagate the logger is not a panacea - its simply another way of flowing things around when you are passing ILogger explicitly (you can use it to wire in the SourceContext via a .ForContext per class, but that's about it)