Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Sep 17 22:52

    ckadluba on dev

    Updated version and CHANGES.md … Merge pull request #355 from ck… (compare)

  • Sep 15 22:51

    nblumhardt on dev

    Use System.Environment.ProcessI… Merge pull request #20 from Num… (compare)

  • Sep 12 16:48

    Jaben on dev

    Fixes #37 Switched to lazy loa… Merge branch 'dev' of https://g… (compare)

  • Sep 12 16:09

    Jaben on dev

    Update README.md (compare)

  • Sep 08 23:06

    nblumhardt on dev

    Update issue template to point … (compare)

  • Sep 02 03:06

    serilog-build on v108

    (compare)

  • Sep 02 03:06

    Jaben on dev

    Merge branch 'dev' Merge pull request #28 from ser… Merge pull request #36 from ser… and 4 more (compare)

  • Sep 02 03:06

    Jaben on v5.0.0

    (compare)

  • Sep 02 03:06

    Jaben on master

    Logs using Native Bson Serializ… Moving to base 5.0 Added example of custom MongoDb… and 9 more (compare)

  • Sep 02 02:55

    Jaben on dev

    Updated mongo db driver (#65) (compare)

  • Aug 31 05:32

    nblumhardt on dev

    constructors with arguments sup… review fix: simplify readme sam… Merge pull request #281 from sk… (compare)

  • Aug 30 23:27

    nblumhardt on dev

    Build and packaging updates -… Merge pull request #169 from nb… (compare)

  • Aug 24 02:29

    nblumhardt on dev

    Update README.md Add section f… Minor consistency tweaks Merge pull request #48 from val… (compare)

  • Aug 20 00:05

    nblumhardt on dev

    Various new features now on `de… (compare)

  • Aug 19 23:31

    nblumhardt on dev

    Moar nullables (#1597) * Upd… (compare)

  • Aug 19 06:31

    nblumhardt on build-updates

    (compare)

  • Aug 19 06:30

    nblumhardt on build-updates

    Build and packaging updates -… (compare)

  • Aug 19 05:57

    nblumhardt on dev

    Merge pull request #56 from ser… New NuGet API Key So we can just use TelemetryCon… and 47 more (compare)

  • Aug 19 05:47

    nblumhardt on master

    (compare)

  • Aug 19 05:39

    nblumhardt on master

    Head back towards the regular S… (compare)

jimkeecn
@jimkeecn
im stupid, i didn't include the sink in the cs file.
raviraj-bhalerao
@raviraj-bhalerao

Hello,

I am using serilog with .netcore31.

I am trying to use different webhostbuilders inside the application to form separate pipelines for different routes/branch.

I would like to have separate logging configuration for each pipeline (branch).

I tried to use UseSerilog but with that I just get latest configuration set using UseSerilog applied to all branches.

So I tried to use AddSeriLog method by supplying externally created logger as parameter to each branch.

The mechanism works well however its very slow.

Do you have any suggestion how to solve the problem?

Nicholas Blumhardt
@nblumhardt
We haven't shipped an RTM of Serilog.Sinks.Console in four years! (The last build was a pretty solid one ;-)) ... New version is finally out - could use some tyre-kicking, if anyone's able to give it a try: https://www.nuget.org/packages/Serilog.Sinks.Console/4.0.0
George Kinsman
@gkinsman
Quick Q re Serilog.Expressions: Using a verbatim string literal with multiple lines and \n seems to cause logs to be emitted on a single line separated by \n, instead of new line separated events. Is this expected? I wanted to separate my expression on multiple lines to make it easy to read, but it broke our log shipper :D
using Environment.NewLine instead of \n makes it work
Jeremy Guinn
@JeremyGuinn
Quick question, can we treat your dev versions as rc (regarding semantic versioning)? It looks like you haven't used rc for a while
Khrystyna Mykhailiuk
@khrystynamykhailiuk:matrix.org
[m]
Hello! I need to write 'Information' logs into different files. F.e. first file will be named 'log-date' and another 'service-date-info'.
I've already have implemented saving logs into daily created 'log-date' files.
And from specific Service I need to write for specific file like 'service-date-info'
How can I do that with Serilog?
I need made some changes in Configuration?
or create separate Logger for it?
Could you please help me?=)
navdii
@navdii
Hi All, How can I encrypt and decrypt a serilog log file in my C# WPF project using VS2019? Are there any settings inside serilog configuration?
Warren Buckley
@warrenbuckley

Question/Advice please - LoggingLevelSwitch & Current Min LogLevel 💬

I have a LoggingLevelSwitch that gets changed at runtime when the user wants to temporally change the Min LogLevel to help collect more logs as needed, which works just great and more Verbose/Debug messages get collected from the initial config being set to Info from appsettings.json

However I have a piece of code that is used to help display the Logger Minimum LogLevel in the UI which after changing the LoggingLevelSwitch now reports incorrectly.

public string GetLogLevel()
{
    var logLevel = Enum.GetValues(typeof(LogEventLevel)).Cast<LogEventLevel>().Where(_serilogLog.IsEnabled).DefaultIfEmpty(LogEventLevel.Information)?.Min() ?? null;
    return logLevel?.ToString() ?? "";
}
1 reply
joaorsfonseca
@joaorsfonseca

hello! i'm having some issues using serilog while running a background task in an uwp app.

I'm using appsettings to configure, but no log is being done.
"Serilog": {
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "%BASEDIR%/logs/log.txt",
"rollingInterval": "Day",
"retainedFileCountLimit": 30,
"shared": true
}
}
]
}

and in my background task i'm doing this:
Environment.SetEnvironmentVariable("BASEDIR", ApplicationData.Current.LocalFolder.Path);
var configuration = new ConfigurationBuilder()
.SetBasePath(ApplicationData.Current.LocalFolder.Path)
.AddJsonFile("appsettings.json")
.Build();

        Log.Logger = new LoggerConfiguration()
            .ReadFrom.Configuration(configuration)
            .CreateLogger();

what i'm doing wrong? or missing?

Roman Marusyk
@Marusyk
Hi, can anyone help me with filtering?
I need to include logs only if the message length is < 250
I've tried, but no logs

Log.Logger = new LoggerConfiguration()
.Filter.ByIncludingOnly("@Level = 'Information' and Length(Message)<5")
.WriteTo.Console()
.CreateLogger();

Log.Information("Cart contains");
Log.Information("Cart");

what's wrong?
Roman Marusyk
@Marusyk
ok, it should be Length(@m)<5
Mark Olbert
@markolbert

I'm a little confused about how ForContext() works when you pass a logger instance down a constructor chain. For example, assume class A creates Serilog logger and calls ForContext(GetType())...and then passes the logger instance to the constructor for class B which then also calls ForContext(GetType()).

When methods in instances of class A and class B log stuff are the log events decorated with the proper type information? Or does "last man win"? :)

Ruben Bartelink
@bartelink
Any given instance of a Logger has a single string associated with the SourceContext key. The .ForContext() methods on a given logger make a fresh instance that replaces the SourceContext with a new value, on a new instance. So if A has a ILogger _logger that it made, and B has one that it made, then they'll be independent. This is all best proven in C# interactive and/or by reading a tutorial such as serilog.net
Mark Olbert
@markolbert
Thanx, Ruben, for the explanation.
gtmacgregor
@gtmacgregor
image.png

Good Evening! Having an issue with outputting JSON to both console and file - I have a simple example which shows the issue but basically I have an object that contains a dictionary<string, object> and when and entry in the contents (not key) contains an equal sign (=) Serilog outputs the valid JSON string missing a closing brace (}).

Snipit:

var jsonString = "{\"Data\":{\"Key1\":\"Data with = sign\"}}";

gtmacgregor
@gtmacgregor

var jsonString1 = "{\"Data\":{\"Key1\":\"Data without equal sign\"}}";

_logger.Error(jsonString);
_logger.Error(jsonString1);

The output in both console and file is:

{"Data":{"Key1":"Data with = sign"}
{"Data":{"Key1":"Data without equal sign"}}

notice the first loge entry with the = sign is missing the closing bracket.

The setup of the logger is:

var _logger = LoggerConfiguration()
.MinimumLevel.Verbose()
.WriteTo.File(@"C:\temp\serilogtest.log", outputTemplate: "{Message}{NewLine}")
.WriteTo.Console()
.CreateLogger();

Any ideas on how to solve this problem (without stripping out the =) would be great.

Thank you!!

Ruben Bartelink
@bartelink
@gtmacgregor the first arg needs to be a format string, i.e. I suspect you'll fare better with _logger.Error("{message}", jsonString) - there is a fantastic Serilog Analyzer package you can install that will alert re such things
gtmacgregor
@gtmacgregor
@bartelink thank you! I will give that a try. Wondering what the difference is as I have the outputTemplate set when I create the logger. Thank you!
Raj
@krisrajzlive
I am new to serilog, how can I write to Windows Eventlog with .Net console app. Any help would be appreciated
Ruben Bartelink
@bartelink
@krisrajzlive would recommend posting details of what you've tried and what the gap is on StackOverflow - if you tag it serilog, anyone that traverses here will see it just as quick (and there's way more traffic there). That and/or googling for a tutorial, which is actually what I'd do!
Gaute Løken
@gautelo
Is there a minimum batchPeriod for the PeriodicBatchingSink? I'm trying to set something like 100ms (for testing purposes) but I'm unable to get consistent results with anything lower than about 1500ms. (Using Serilog.Sinks.Datadog.Logs which inherits the PeriodicBatchingSink, in case that's relevant.) What I'm doing is modifying a custom ILogEventFilter and the minimum level using a LoggingLevelSwitch at runtime. I'm trying to figure out when I can guarantee that the new values are in effect, and I was hoping that if I waited the batchPeriod I would have that guarantee. It appears that's not the case, so I wonder what's going on.
Nicholas Blumhardt
@nblumhardt
@gautelo the batch time will be in addition to whatever the time taken to actually ship the batch to the destination service is
Gaute Løken
@gautelo
@nblumhardt In addition to the round trip time or just the time to fire and forget? Hmm.. how do I test how long that part takes I wonder? Since I'm sending a relatively small number of logs I expect the payload size is small and most of the time is the latency/ping. That really should not be much more than say 100ms or 150ms..
kjkombat
@kjkombat
Hi, im new to asp.net and i'm trying to get logging into file working with serilog but facing some issues. I've given further details in a stackoverflow post. Much appreciated if anyone gives it a look. https://stackoverflow.com/questions/69014420/serilog-not-recording-logs-to-file-when-i-publish-app
Thomas
@ThomasRizzo
Hi, I have a clef file with entries like this except 'ExtraInfo' has a ton of fields:
{"@t":"2021-09-01T17:14:03.9903859Z","@mt":"{Test}: {Result}","Test":"XYZ","Result":"Pass","ExtraInfo":{"Thing1":false,"Thing2":true,"$type":"ExtraInfo"}}
How can I just pluck out Test,Result and 'Thing2' in a template?
Aayush
@aayushvetwal
I need to have two MSSqlServerSettingsSections for two different tables. The columns for the two tables are entirely different and have to be configured separately. How can I do that?
kingcomxu
@kingcomxu
Hi, everyone, im new to serilog, how can i remove {ActionId ActionName RequestId RequestPath ConnectionId} Properties from log entry? thanks
edje
@projectje
I am using serilog in our solution (50 projects) which works. But in hindsight maybe i configured it wrong. I noticed that I can not do "_logger.ForContext" because it says it is unknown. I include in my services using Microsoft.Extensions.Logging; but I do not include using Serilog.
When I use "using Serilog" I notice i can no longer pass ILogger<> _logger but instead need to do ILogger _logger and also can no longer do _logger.LogInformation but need to do _logger.Information . But once i do during runtime it gives a dependency error of that interface no being defined. So ...somewhere i do something wrong then.
I came to this because every of the 50 projects has a unique "tag" in the Settings class of the specific project. I now wanted to by default add the "tag" as property for each of the projects (and each project has multiple services). I am currently doing this with "{Tag}", _settings.Tag but i came across .ForContext and so ending up with this question
Ruben Bartelink
@bartelink
@projectje The Microsoft.Extensions.Logging stuff provides a different API surface which wraps Serilog.
You may be able to achieve the same as ForContext with the BeginScope mechanism in there
Alternately, some people use Serilog directly - in that case, as you've noticed, you lose the ability to have the automatic class name tagging that the generic ILogger gives
You'll need to pick your poison
If you google serilog ILogger vs Microsoft Extensions ILogger or similar you should find a decent overview article and/or canonical SO answer on this
edje
@projectje
Ah ok, so that means .ForContext can not be used when "using Microsoft.Extensions.Logging" but to achieve the same you need to write something else.
Ruben Bartelink
@bartelink
well MEL ILogger's BeginScope is equivalent in power/function to ForContext - i.e. it essentially delegates to that
edje
@projectje
Thanks , i will check the links and beginscope
Ruben Bartelink
@bartelink
Its definitely reasonable to use MEL ILogger, and wanting to add context properties definitely should not trigger needing to replace with direct Serilog.ILogger (although using it directly is a common enough thing that people do)
edje
@projectje
Using Beginscope inside a method is fairly straightforward but to set it per project will require some more thinking.
Nicholas Blumhardt
@nblumhardt
@gautelo round-trip time as well :+1:
@ThomasRizzo what kind of template do you mean?
@kingcomxu where are you writing the log entries to/in which format? If it's text or JSON, ExpressionTemplate should cover this (check the JSON or text examples in the recent two posts on nblumhardt.com); if it's something like Seq, see serilog/serilog#1373 (some code in there)
Steffen Hansen
@shasystemate_gitlab
Hi,
How would one approach invoking Destructure.AsScalar<T>() on particular subloggers only?
For now, I've solved the issue by maintaining two entirely separate top level loggers. But this prevents me from using the global Log.Logger, which is turning out to be not very pretty.
Aayush
@aayushvetwal
Installed Serilog.Sinks.MsSqlServer 5.6.0 package in my .net web api project. Works fine in local. When deployed to server, gives 502 error. Don't know the reason why it happens.
bdovaz
@bdovaz
@nblumhardt can you publish a non preview logging package? Thanks https://www.nuget.org/packages/Serilog.Extensions.Logging/
Sasha
@sasha-khadasevich
Hello
Does anyone have any ideas, why dynamically load of dll in my case broken?
serilog/serilog-settings-configuration#283