Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Dec 02 15:30

    MiguelAlho on dev

    Add .NET Standard 2.0 target fr… (compare)

  • Nov 26 21:07

    mivano on dev

    Adding aliases when creating in… (compare)

  • Nov 25 01:55

    nblumhardt on dev

    Add mote Tests to MessageTempla… Add more tests to MessageTempla… Add more tests to MessageTempla… and 1 more (compare)

  • Nov 22 21:47

    nblumhardt on dev

    add applyThemeOnOutputRedirecti… fix typo add unit tests and 5 more (compare)

  • Nov 22 21:42

    nblumhardt on dev

    Configurable sync root for cons… Fix accidental spaces revert sample changes and 5 more (compare)

  • Nov 22 21:42

    nblumhardt on dev

    Incoming breaking changes (compare)

  • Nov 21 23:07

    nblumhardt on dev

    add support to AuditTo.Logger add unit test Merge pull request #202 from al… (compare)

  • Nov 18 22:15

    nblumhardt on master

    Small layout improvement (compare)

  • Nov 18 22:14

    nblumhardt on master

    Replace obsolete Groups link wi… (compare)

  • Nov 18 22:11

    nblumhardt on master

    Update index.html Merge pull request #6 from dogg… (compare)

  • Nov 13 07:10

    mivano on dev

    Fixed two issues regarding Buff… (compare)

  • Nov 12 02:45

    serilog-build on v3.2.0

    (compare)

  • Nov 12 02:44

    serilog-build on v137

    (compare)

  • Nov 12 02:44

    nblumhardt on dev

    Dev version bump [skip ci] (compare)

  • Nov 12 02:44

    nblumhardt on master

    Dev version bump [skip ci] Add RequestHost & RequestScheme… Remove spaces and 12 more (compare)

  • Nov 08 22:54

    mivano on v8.0.1+5.build.378

    (compare)

  • Nov 08 04:39

    nblumhardt on dev

    FIX: Enrich context before coll… Merge pull request #149 from pu… (compare)

  • Nov 08 04:35

    nblumhardt on dev

    Fixes #50 - package license not… (compare)

  • Nov 06 02:55

    nblumhardt on dev

    Now supports `options.EnrichDia… (compare)

  • Nov 06 02:54

    nblumhardt on dev

    Request logging and provider su… (compare)

tleylan
@tleylan
@nblumhardt thanks again... I'll play some more
coltsfanatic07
@coltsfanatic07
I implemented Serilog on a .NET Core 2.2 project. Everything is logging and beautiful. I have enrichment and properties coming out on my development machine, but when I move the project to RHEL, I get none of the enriched level data (ie no action info, no request id, no correlation data etc.). Any clue why it would behave differently on RHEL? The only thing that is different between the deployments is my local windows machine is using the DEBUG sink where I am using a File sink wrapped with ASYNC on the Linux side.
coltsfanatic07
@coltsfanatic07
@coltsfanatic07 Found it. My outputTemplate was at the ASYNC level and not the FILE sink level. Moved the configuration and now its magical everywhere. Thank you!
Mel Grubb
@MelGrubb

I'm having significant trouble getting the simplest of things configured here. I want to write log messages to Application Insights, but I've dialed it back to just trying to get the console to work at this point. I have this working through code-only configuration, but I really need to be able to control this from the config file, so I've added Serilog.Settings.AppSettings, and I'm not getting anywhere. Here's my simplest example. Can anyone tell me what's wrong with it?

    <add key="serilog:using:Console" value="Serilog.Sinks.Console"/>
    <add key="serilog:write-to:Console"/>
    <add key="serilog:write-to:Console.logEventLevel" value="LogEventLevel.Information" />

I've tried both "Information" and "LogEventLevel.Information". Neither seems to do anything.

Mel Grubb
@MelGrubb

Update: I'm having better luck with Serilog.Sinks.Debug. It seems to work for me now, so I at least know that the configuration is being read. Now I just need to get the ApplicationInsights sink set up, but it's much the same. I'm just not getting anything reported. Here are the lines from my app.config

    <add key="serilog:minimum-level" value="Debug" />

    <add key="serilog:using:ApplicationInsights" value="Serilog.Sinks.ApplicationInsights" />
    <add key="serilog:write-to:ApplicationInsightsEvents.instrumentationKey" value="..." />
    <add key="serilog:write-to:ApplicationInsightsEvents.logEventLevel" value="Information" />

    <add key="serilog:using:Debug" value="Serilog.Sinks.Debug" />
    <add key="serilog:write-to:Debug.logEventLevel" value="Debug" />

And here is the config code

            Log.Logger = new LoggerConfiguration()
                .ReadFrom.AppSettings()
                .CreateLogger();

Is there anything obviously wrong here?

Mel Grubb
@MelGrubb
I've made the assumption that the only examples I could find on the web are all wrong, and that the name on the "using" line should exactly match those on the "write-to" line, so they all say "ApplicationInsights" now, but it still doesn't log anything that I can find. I've reverted to setting up that sink in code for now. Oh well.
coltsfanatic07
@coltsfanatic07
Man this site is blocking off the last line. I'm using a JSON file in appsettings.json so completely different config, but I did go through some trials and tribulations putting various people's work together before I hit the sweet spot. Seemed odd to me at the time as well, but I chopped it up to changes in .NET CORE from release to release. I will try help if I can. What type of app are you working with?
Mel Grubb
@MelGrubb

It's a full-framework (not Core) Web API. The next version will be .Net Core, but that's a whole new project, I'm afraid. In the meantime, I'm trying to add some logging to the existing system for monitoring the progress of certain background jobs. The code-only configuration currently looks like this:

            Serilog.Debugging.SelfLog.Enable(msg => Debug.WriteLine(msg));
            TelemetryConfiguration.Active.InstrumentationKey = ConfigurationManager.AppSettings["APPINSIGHTS_INSTRUMENTATIONKEY"];
            Log.Logger = new LoggerConfiguration()
                .WriteTo.ApplicationInsights(TelemetryConfiguration.Active, TelemetryConverter.Events, LogEventLevel.Information)
                .CreateLogger();

I'd like to do this from AppSettings because they are easily controlled on a per-environment basis through Azure, where the API is hosted. I could do this through a separate config file (json or otherwise), but per-environment appsettings are already used to control other configuration differences between environments on this project, so keeping that same mechanism would be a huge help.

Anyway, I burned nearly a whole day yesterday trying to get the ApplicationInsights sink to configure and fire up through AppSettings, and got nowhere. I've fallen back to the code-based example above. I'm still willing to try any suggestions of how to set up Serilog.Settings.AppSettings though. I think it would be cleaner to use the official support rather than hacking around it myself.

Sean Fausett
@gitfool
I want to configure a console sink with code when it's not already configured via config (in .NET Core)
Is there a better way other than checking the config directly? e.g.
var writeToConsole = context.Configuration.GetSection("Serilog:WriteTo").GetChildren().Any(x => x.GetSection("Name").Value == "Console");
Ideally, there's an easy way to check for this after running:
config.ReadFrom.Configuration(context.Configuration)
Nicholas Blumhardt
@nblumhardt
@MelGrubb thanks for sharing your experiences. Unfortunately I'm not clued up enough on how that sink works/is configured, but posting some details to Stack Overflow (serilog tag), or in an issue to https://github.com/serilog/serilog-sinks-applicationinsights, might get some more eyes on it.
@gitfool no, I think the workaround you're using is the only option available at this point
Sean Fausett
@gitfool
Okay. FTR, I tweaked it slightly:
var writeToConsole = context.Configuration.GetSection("Serilog:WriteTo").GetChildren().Any(section => section.GetValue<string>("Name") == "Console");
Quite handy when devs can create the console sink with settings they prefer when using local Development environment
Just need to specify environment variables once for all projects that support this:
"Serilog__WriteTo__0__Name" = "Console"
"Serilog__WriteTo__0__Args__theme" = "Serilog.Sinks.SystemConsole.Themes.ConsoleTheme::None, Serilog.Sinks.Console"
"Serilog__WriteTo__0__Args__outputTemplate" = "[{Timestamp:HH:mm:ss} {Level:u3}] ({SourceContext}) {Message:lj}{NewLine}{Exception}"
Artur Krajewski
@krajek
Hi, I have a question to which probably answer is "no" :-), but just to be sure I did not miss anything: Can I filter properties of log events I did not produce?
For example, EntityFramework logs some events, but I am sure I do not care about "commandTimeout" or "commandType". I would like to remove them to save network bandwidth.
Nicholas Blumhardt
@nblumhardt
Hi @krajek - yes, you can remove them by implementing ILogEventEnricher, and calling RemovePropertyIfPresent("commandTimeout") etc. on the LogEvent passed to the enricher. Let me know if you need more info. Cheers!
Nicholas Blumhardt
@nblumhardt
@krajek also interested in your feedback on serilog/serilog#1373 - similar functionality proposed for the core
Artur Krajewski
@krajek
thanks @nblumhardt, after all this time with Serilog, I had no idea RemovePropertyIfPresent existed :-)
obviously, ByRemovingProperty is what I would like to see in the library :+1
Artur Krajewski
@krajek
Maybe few remarks: ByRemovingProperties could also by useful
accepting params string[]
and additionally an overflow of ByRemovingProperty which would accept some kind of predicate or at least SourceCountext
so client can, for example, remove ActionName property but only for non-ASP.NET Core logs
(so that ActionName would be logged just once, and not repeated on every subsequent log event)
Nicholas Blumhardt
@nblumhardt
:+1: thanks for the notes, @krajek
Arif
@deararif_twitter
Hi, Can i add CustomLogEvent with Serilog, If so then how? Like I want to add something like - LogEventLevel.MyCustom
Ruben Bartelink
@bartelink
@deararif_twitter you can add an enricher that maps a serilog level to a different string and adds it to the prroperties; you then reference that value in your output template (actually for real adding yet another level would serve no purpose I can imagine?)
Arif
@deararif_twitter
Hi Rube, Thanks a lot for your kind response. can you please get me a code sample as i switched from log4net and kind of new here ...
Arif
@deararif_twitter
@bartelink Thank you much!
Sumit Bansal
@sumit4bansal
Does serilog-sinks-mssqlserver write logs in SQL server asynchronously?, How can I skip logging of some custom exception type using Serilog? I am trying to move from Log4Net
Ruben Bartelink
@bartelink
@sumit4bansal there's a serilog.sinks.async package that you use to wrap other sinks - if you google about you'll find relevant blog posts etc. The DSL provides a way to filter things of all kinds (but stackoverflow is the best place to search for such things)
Nicholas Blumhardt
@nblumhardt
@sumit4bansal @bartelink the MSSQL sink is based on PeriodicBatchingSink and does batched/async writes by default :+1:
Dayne
@Swaggadan
is there a way to use Serilog without the dll files? I am trying to have the console app (exe) alone.
Dayne
@Swaggadan
is there a way to get line number in log?
Arif
@deararif_twitter
Hi Guyz, How can i encrypt and decrypt a serilog log file in code? Is there any settings inside serilog configuration?
Ruben Bartelink
@bartelink
I'd say if it needs to be encrypted, you should be managing this at a lower level. While it's technically possible (there may even be a way in the File Sink to enable wrapping the stream in the box), its just a bad idea.
re File line numbers, I'd suggest use VS Code and turn on line numbers. maintaining a line number would require the writer to count the lines on init and then deal with mess with concurrent writers
re not having DLL files, serilog is definitely not a single .cs file sized thing - you can use ILMerge or ILRepack to merge it (and any sinks) into your EXE, though in general I'd ask "why" - e.g. if you pack s a dotnet tool then you have a single referenceable thing (which can ref other nugets)
Arif
@deararif_twitter
Hi Ruben, I coudn't catch your answer, any sample code?
Ruben Bartelink
@bartelink
@deararif_twitter Dont have any sample code - I'm suggesting its a bad idea. I recall scanning the serilog.sinks.file repo and issues and suspect there is a way to hook in a custom file stream - the tests would demonstrate how. (encryption in .net is typically layered in over the stream writer as a decorator)
Arif
@deararif_twitter
okay Ruben thanks for your kind reply.
Richard Tasker
@ritasker
I am using the elastic search sink. Am I right in thinking I have to pass the ES creds as an auth token? "connectionGlobalHeaders" :"Authorization=Bearer SOME-TOKEN".Where SOME-TOKEN is the usr:pwd base64 encoded?
Kirtisagar
@kirtisagar
Hi, does anybody use Serilog Metrics in DotNetCore ? https://github.com/serilog-metrics/serilog-metrics
Nicholas Blumhardt
@nblumhardt
@kirtisagar yes, I believe so (it supports .NET Standard 2.0), are you hitting issues?
Mtech Pvt Ltd
@AdimUser

Hi Team, I am new to Serilogs, while I am configuring the serilogs in core 3.0, I am experiencing a wired issue, I am trying to log the http events into console, but I can see the log on the console, only I stop the application, while it is running it does not log the http event to console, after I stop the application, it dump all the logs event to console .

please help me!

The thread 1018762 has exited with code 0 (0x0).
The program '[45975] LoggingApi.Edge.dll' has exited with code 0 (0x0).
[22:58:06 INF] Now listening on: http://localhost:5000 [22:58:07 INF] Application started. Press Ctrl+C to shut down. [22:58:07 INF] Hosting environment: Development [22:58:07 INF] Content root path: /development/logging-api/LoggingApi.Edge
Mtech Pvt Ltd
@AdimUser

Hi Team, I am new to Serilogs, while I am configuring the serilogs in core 3.0, I am experiencing a wired issue, I am trying to log the http events into console, but I can see the log on the console, only I stop the application, while it is running it does not log the http event to console, after I stop the application, it dump all the logs event to console .

please help me!

The thread 1018762 has exited with code 0 (0x0).
The program '[45975] LoggingApi.Edge.dll' has exited with code 0 (0x0).
[22:58:06 INF] Now listening on: http://localhost:5000 [22:58:07 INF] Application started. Press Ctrl+C to shut down. [22:58:07 INF] Hosting environment: Development [22:58:07 INF] Content root path: /development/logging-api/LoggingApi.Edge

more details : https://stackoverflow.com/questions/59191789/serilog-logs-only-after-application-stop

Kirtisagar
@kirtisagar
@nblumhardt the issue is when we use DotNet core extension Microsoft.Extensions.Logging we don't get the BeginTimedOperation since its not part Microsoft.Extensions.Logging.ILogger we may have to rewrite the extension method for Serilog Metrics.
any other tips?