Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Dec 01 22:42

    serilog-build on v42

    (compare)

  • Dec 01 22:42

    nblumhardt on dev

    Dev version bump [skip ci] (compare)

  • Dec 01 22:41

    nblumhardt on master

    Dev version bump [skip ci] Doc updates; fixes #19 Mention absence of XML/JSON con… and 7 more (compare)

  • Dec 01 22:40

    nblumhardt on dev

    Update publishing key (compare)

  • Dec 01 22:34

    nblumhardt on dev

    Tooling updates Packaging updates; add a net5.0… Merge pull request #28 from nbl… (compare)

  • Nov 25 15:20

    ckadluba on dev

    added support for reserved colu… Merge pull request #332 from su… (compare)

  • Nov 24 06:55

    nblumhardt on dev

    make '$' sign optional for mini… Merge pull request #242 from sk… (compare)

  • Nov 23 06:39

    nblumhardt on dev

    FilterSwitches support merge from dev added Serilog.Expressions suppo… and 4 more (compare)

  • Nov 20 20:26

    nblumhardt on dev

    misc fixes: - DependencyContext… DependencyContextAssemblyFinder… changelog update and 1 more (compare)

  • Nov 13 12:34

    ckadluba on v385

    (compare)

  • Nov 13 08:43

    serilog-build on v5.6.0

    (compare)

  • Nov 12 09:43

    mivano on enable-code-ql

    (compare)

  • Nov 12 09:42

    mivano on dev

    Create codeql-analysis.yml (#37… (compare)

  • Nov 12 09:31

    mivano on enable-code-ql

    Create codeql-analysis.yml (compare)

  • Nov 10 22:35

    nblumhardt on dev

    Add ability to capture path of … Merge pull request #189 from au… (compare)

  • Nov 09 09:05

    nblumhardt on dev

    Deprecation notice [skip ci] (compare)

  • Nov 09 09:01

    nblumhardt on dev

    Update project to use SPDX Lice… Add embedded icon to NuGet pack… Merge pull request #190 from au… (compare)

  • Nov 06 23:34

    serilog-build on v385

    (compare)

  • Nov 06 23:33

    ckadluba on master

    Bumped version number. Merge remote-tracking branch 'u… Merge pull request #309 from ck… and 17 more (compare)

  • Nov 06 23:29

    ckadluba on dev

    Documented changes for release … Merge pull request #325 from ck… (compare)

Tal McMahon
@TalMcMahon
I just add to the string itself. I add tilda or spaces something so that the log is a bit easier to scan/search on
Weston
@ronnyek
like you just look for the tildes or it actuially translates that into a highlight
Tal McMahon
@TalMcMahon
like Log.LogInformation("=====>Service Started")
Weston
@ronnyek
because console logger has literateconsole functionality
where if you use string format, it'll actually color the substitued values or whatever
Tal McMahon
@TalMcMahon
Oh, sorry. I meant in the file sink
my bad
Weston
@ronnyek
hmm... actually the syntax highlighting doesnt do the trick
with a string format
I dont see it documented anywhere
Tal McMahon
@TalMcMahon
yeah thats why I ended up here.
worked for both
I mean with the string format answer
Weston
@ronnyek
I know literate console does do that, for some things
like I had a string I was formattign
{someNumber: {{0:0.00}}}
and it was highlighting that, but leaving the {{}} in the highlighted code
I'd just like to say logger.LogInformation("count: {0}",20) and have 20 automatically highlighted in something thats not the regular logging color
Weston
@ronnyek
I bet when I was seeing it highlight stuff, I bet it just thought that was json
erikljung
@erikljung
Hi, probably a stupid question, but maybe someone has a creative solution to my unconventional issue. I would like to create a logger with MinimumLevel = Warning for all sinks, but i also want to collect all logs in a special sink regardless of the MinimumLevel . I know restrictedToMinimumLevel can be set per sink, but that is not flexible enough for me.
Ruben Bartelink
@bartelink
@erikljung Id say this is worth asking on SO. Main problem I see is that each logger chain has a min level (defaulting to Information, which filters them before they get to the sinks). Adding the sink to grab all warnings into the config is the easy bit.
Nathan Skerl
@nskerl
@erikljung have you looked into subloggers? You could send the conditional stream to an entire new logger which has your special sink
erikljung
@erikljung
@bartelink @nskerl Thanks for your answers. I've already solved the problem by setting restrictedToMinimumLevelfor all other sinks and keeping the LoggerConfiguration unlimited. It would probably not be the optimal solution regulary, but I had a very unimportant usecase. I will however check out the sublogger thing.
MyFleetCenter
@MyFleetCenter
Hello, is there a way to use the Elasticsearch sink to write to Enterprise search on Elastic Cloud? I can upload using Postman without issue, but trying to upload it using my C# api application shows me this in Fiddler: {"errors":"Routing Error. The path you have requested is invalid."}. I found this on SO regarding Nest and Enterprise search but not sure if it also applies to the Elasticsearch sink : https://stackoverflow.com/questions/64137515/search-issue-with-elasticsearch-nest-routing-error-the-path-you-have-requeste
zcarson
@zcarson
Hello, I'm using the Http sink to forward my log messages to another service. I need to have the message shaped into a specific PoCo that should contain values based on the appsettings.json. I've tried injecting the IOptions into a custom ITextFormatter, but it is complaining that there is no default constructor. Is there an easy way to get config values into the textFormatter, or another way to get those values in? Once that problem is solved, I have a similar issue with getting an Authkey into the request headers that the Http sink is sending, but I havent started tackling that yet so it may be easier.
Thibaud Desodt
@tsimbalar
maybe https://stackoverflow.com/questions/50387469/net-core-and-serilog-email-sink-json-config/50580020#50580020 can help ?
Otherwise I'd suggest posting a question on stackoverflow with the serilogtag
zcarson
@zcarson
Coworker suggested adding it to a WithProperty Enricher; seems to have done the trick
danushkap
@danushkap

Hi, could you please suggest a better approach to handle this Log duplicate. thank you.

Also, Q2) what are the implications of plugging in the SerilogRequestLogging middleware at the very top of the request processing pipeline, like:

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    app.UseSerilogRequestLogging();
    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
        app.UseDatabaseErrorPage();
    }
    else
    {
        app.UseExceptionHandler("/Error");
    }
    app.UseStatusCodePagesWithReExecute("/StatusCode/{0}");
}

having the SerilogRequestLogging middleware after the StatusCodePagesWithReExecute will duplicate the log entries, due to the pipeline re-execute that take place in StatusCodePagesWithReExecute or ExceptionHandler middleware(s), see below

[19:29:14 INF] [Serilog.AspNetCore.RequestLoggingMiddleware] HTTP GET /foo/bar responded 404 in 0.1028 ms
[19:29:14 ERR] [XYZ.ErrorController] [0HM3K6SI40FUF:00000003] Request /foo/bar finished in HTTP 404
[19:29:14 INF] [Serilog.AspNetCore.RequestLoggingMiddleware] HTTP GET /foo/bar responded 404 in 4.9369 ms

Plugging in the SerilogRequestLogging at the very top of the pipeline solves this issue,
But is it a good idea to do it that way?
(One repercussion that i can think of is, after doing this, the ExceptionHandler middleware(s) will not handle any exceptions that may occur inside the SerilogRequestLogging middleware)

Is this recommended? Or is there a better way to avoid the log duplicate?

Abhinav Kant
@abhinavkant007_gitlab
Hi Everyone, i am facing an issue SerilogError : 2020-10-30T08:15:36.0810424Z Ignoring added logger provider Serilog.Extensions.Logging.SerilogLoggerProvider The code is deployed on IIS build on dotnet core 2.2, the strange thing is if I copy the deployed artifact on any other server serilog is able to log use its sinks.
Ruben Bartelink
@bartelink
@abhinavkant007_gitlab best to ask on stackoverflow.com with as much context as you can add
Also perhaps check the Serilog SelfLog for diagnostic messages
danushkap
@danushkap

Having the SerilogRequestLogging middleware after the StatusCodePagesWithReExecute duplicates the log entries (see below),
When there are errors such as 404.
I suppose this is due to the pipeline re-execute that take place in StatusCodePagesWithReExecute or ExceptionHandler middleware(s)

[19:29:14 INF] [Serilog.AspNetCore.RequestLoggingMiddleware] HTTP GET /foo/bar responded 404 in 0.1028 ms
[19:29:14 ERR] [XYZ.ErrorController] [0HM3K6SI40FUF:00000003] Request /foo/bar finished in HTTP 404
[19:29:14 INF] [Serilog.AspNetCore.RequestLoggingMiddleware] HTTP GET /foo/bar responded 404 in 4.9369 ms

Plugging in the SerilogRequestLogging at the very top of the pipeline solves this issue, as:

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    app.UseSerilogRequestLogging();
    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
        app.UseDatabaseErrorPage();
    }
    else
    {
        app.UseExceptionHandler("/Error");
    }
    app.UseStatusCodePagesWithReExecute("/StatusCode/{0}");
}

But is this the right way to do it?
(One repercussion that i can think of is, after doing this, the ExceptionHandler middleware(s) will not handle any exceptions that may occur inside the SerilogRequestLogging middleware)
Or is there a better way to handle this Log duplicate?

zakiahmed-worldvision
@zakiahmed-worldvision
Is it possible to dynamically update the Serilog filepath. Serilog initialisation is in Startup.cs. But I am trying to dynamically update the Serilog filepath from an API call to my controller method which takes in the fileName. e.g. .WriteTo.AzureBlobStorage(filePath)
David de Lucca
@daviddelucca

Hey there! I'm trying to create an enricher to log additional information but I don't think it's working because it's not being called:

  "Serilog": {
    "Using": [
      "Serilog.Sinks.Console",
      "Serilog.Settings.Configuration"
    ],    
    "MinimumLevel": {
      "Default": "Information",
      "Override": {
        "System": "Warning",
        "Microsoft": "Warning"
      }
    },
    "WriteTo": [
      {
        "Name": "Console",
        "Args": {
          "formatter": "Serilog.Formatting.Compact.RenderedCompactJsonFormatter, Serilog.Formatting.Compact"
        }
      }
    ],
    "enrich": [ "WithMyCustomLog" ]
  },

And the code is:

        public static LoggerConfiguration WithMyCustomLog(this LoggerEnrichmentConfiguration enrich)
        {
            if (enrich == null)
                throw new ArgumentNullException(nameof(enrich));

            return enrich.With<OpenTracingContextLogEventEnricher>();
        }

Is it missing some information?

David de Lucca
@daviddelucca
I think the enrich configuration is not being called by serilog because my function is never called
MyFleetCenter
@MyFleetCenter

I have Serilog working locally (sends logs to Elasticsearch), but when I deploy to AWS Lambda, I am getting the following error in the Cloudwatch Logs: System.InvalidOperationException: Unable to resolve service for type 'Serilog.Extensions.Hosting.DiagnosticContext' while attempting to activate 'Serilog.AspNetCore.RequestLoggingMiddleware

Any ideas what the issue could be?

Thibaud Desodt
@tsimbalar
@daviddelucca you are probably missing som "Using" for the assembly containing your extension ?
Maybe https://github.com/tsimbalar/serilog-settings-comparison/blob/master/docs/README.md#method-discovery can ehlp ?
also maybe the example in https://stackoverflow.com/a/50580020/474763 can help
Khizar Iqbal
@EngrKhizarIqbal

Hi All, I'm working on integrating serilog to one of our projects and I want to log only certain logs to the database for DB sink
Here is my Program.cs

public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .UseSerilog(
                    (hostingContext, loggerConfiguration) =>
                    {
                        loggerConfiguration.ReadFrom.Configuration(hostingContext.Configuration)
                        .WriteTo.Logger(config =>
                        {
                            config.ReadFrom.Configuration(hostingContext.Configuration, "SubLogger");
                        });
                    },
                    writeToProviders: true)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();
                });

And here is my settings json

"SubLogger": {
    "Using": [ "Serilog.Sinks.MariaDB", "Serilog.Expressions" ],
    "WriteTo": [
      {
        "Name": "MariaDB",
        "Args": {
          "connectionString": "",
          "restrictedToMinimumLevel": "Information",
          "autoCreateTable": true,
          "tableName": "logs",
          "options": {
            "HashMessageTemplate": true,
            "TimestampInUtc": true,
            "EnumsAsInts": false,
            "ExcludePropertiesWithDedicatedColumn": true,
            "LogRecordsCleanupFrequency": "1.00:00:00",
            "LogRecordsExpiration": "07.00:00:00"
          }
        }
      }
    ],
    "Filter": [
      {
        "Name": "ByIncludingOnly",
        "Args": {
          "expression": "StartsWith(SourceContext, 'OurContext')"
        }
      }
    ]
  },

  "Serilog": {
    "Using": [ "Serilog.Sinks.Debug" ],
    "WriteTo": [
      "Debug"
    ],
    "Enrich": [ "FromLogContext" ],
    "MinimumLevel": {
      "Default": "Information",
      "Override": {
        "Microsoft.AspNetCore": "Debug",
        "Microsoft.EnttiyFrameworkCore": "Debug",
        "System": "Debug"
      }
    }
  }

I've read about subloggers and checked example config from here and tried to give it a shot but failed.
Above code is working but I really want to use MariaDb sink as sub logger.
Can anyone please guide me on how can I configure MariaDb sink as sub logger

Marco Dissel
@mdissel
I just posted a question on stackoverflow
Nicholas Blumhardt
@nblumhardt
:+1:
xzuttz
@xzuttz

Hi,

I am seeing some weird behavior in my custom sink, and would like to debug it.

How would I go about logging an internal Sink exception in another Sink ?

Say I have my own custom batched sink, and throw an exception like this in the OnEmptyBatchAsync method:

        public async Task OnEmptyBatchAsync()
        {
            throw new Exception("Moo");
            await Task.CompletedTask;
        }

Because I've bootstrapped Serilog with .WriteTo.Console() id like to see the exception message in the Console sink.

I'm not seeing the exception message in the Console sink unfortunately. All I get is

"Exception thrown: 'System.Exception' in MyCustomSink.dll"

in the Debug window.

Károly Ozsvárt
@arphox
Hi! This may be a dumb question so I ask it here: does logging block? for example, if I have a sink that logs to elasticsearch, and that works slowly, does this affect my code?
For example I want to use Serilog to log events but it must not slow down my code by any measurable amount.
matrixbot
@matrixbot
iinuwa I would think it would depend on the sink? It looks like the Elasticsearch sink buffers locally, submits a batch of requests asynchronously to Elasticsearch, then handles the responses synchronously.
https://github.com/serilog/serilog-sinks-elasticsearch/blob/dev/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticSearchSink.cs#L57
Thibaud Desodt
@tsimbalar
@arphox It depends on the sink but :
from the"Used By" section of https://www.nuget.org/packages/Serilog.Sinks.PeriodicBatching/ you get an idea of which package already support that
Thibaud Desodt
@tsimbalar