How Structured Logging With Serilog Can Make Your Life Easier

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 ต.ค. 2024

ความคิดเห็น • 88

  • @MilanJovanovicTech
    @MilanJovanovicTech  ปีที่แล้ว +5

    Get the source code for this video for FREE → the-dotnet-weekly.ck.page/serilog
    Want to master Clean Architecture? Go here: bit.ly/3PupkOJ
    Want to unlock Modular Monoliths? Go here: bit.ly/3SXlzSt

    • @coding-in
      @coding-in ปีที่แล้ว

      where 'IsFailure' come from?

  • @KarthikS30712
    @KarthikS30712 7 หลายเดือนก่อน +2

    Hi Milan. I recently discovered your channel and appreciate your extent of coverage in chosen topics.
    I also greatly appreciate how you separate the chapters/sections so I don't pause the video early on and look for "not hardcoing serilog config in programcs" elsewhere; because you've made it clear that it was covered in a future chapter.
    Cheers!

  • @StephaneDroletGolf
    @StephaneDroletGolf ปีที่แล้ว +3

    I really like Serilog. I started to use it in 2019. It has been really helpful and saved me a lot of debugging time. Thank you for adapting it to modern technology.

  • @samerelsahih
    @samerelsahih ปีที่แล้ว +14

    Interesting video, I love serilog. If you can make a video on serilog + elastic search (from a sink) + kibana (also from a sink), it would be pretty sick :)

  • @zoltanzorgo
    @zoltanzorgo ปีที่แล้ว +2

    I have just switched to serilog - I was using your video as starting point, so thank you. Hence I am by far no expert of the field. I have found cumbersome to work with the array-style configuration, especially when overriding from environment - as it needs indexing. There is however - since quite a while actually - a syntax that allows to use an object with descriptive keys instead. This takes advantage of how the configuration infrastructure works in dotnet. And the cool part is, that you can leverage this even further by compacting the overrides in environment-specific appsettings. Like this for example:
    "Serilog:WriteTo:Async:Args:configure:MyDescriptiveLogFileSinkKey:Args": {
    "retainedFileCountLimit": 1,
    "RollingInterval": "Infinite",
    "formatter": "Serilog.Formatting.Json.JsonFormatter, Serilog"
    },
    Quite simpler than providing the whole structure.

  • @LesGainous
    @LesGainous ปีที่แล้ว +2

    I was hoping you would show the details on using SQL Server and how to log to it, such as auto-creation of a log table, the columns to includes, etc. Maybe a future video??

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว

      Definitely a future video, going to cover a few Serilog Sinks

    • @SunkenMax
      @SunkenMax ปีที่แล้ว

      Hey did you come across anything which helps us generate log table, it's columns and log our event in that table? Please it'll be very helpful if you have found something and if you'd share that

  • @eduardrivas6964
    @eduardrivas6964 ปีที่แล้ว +3

    Milan, do you have the creation process of full projects on video? or even in a course? I'm a big fan of learning through doing ant not just watching, and watching you and repeating the process of building a complete project applying some patterns, principles and good practices, would be amazing, I would pay to see that and learn from your experience.

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว +1

      Working on a course right now! Should be out in July/August. There are a few "from scratch" videos, but nothing that goes 0 to hero

  • @raularmas7835
    @raularmas7835 ปีที่แล้ว +1

    Great video Milan !

  • @theeusftn
    @theeusftn หลายเดือนก่อน

    i've a question. I can put this logs in each endpoint? For example, I've a endpoint to update one list and when this list update create a log

    • @MilanJovanovicTech
      @MilanJovanovicTech  หลายเดือนก่อน +1

      Sure - if that information is important for you

    • @theeusftn
      @theeusftn หลายเดือนก่อน

      @@MilanJovanovicTech that's great, ty man

  • @adahadapato
    @adahadapato ปีที่แล้ว +1

    Hi Milan, I really enjoy your works, i mean you have demonstrated how easy it is to adapt to any programing construct.
    Please do you have a repo for these source codes.
    Thnk you again

  • @salmanshafiq8151
    @salmanshafiq8151 ปีที่แล้ว +1

    Nice Video. Which theme are you using? Your color scheme are better and difference than as usual visual studio provides as default.

  • @NemesisA5
    @NemesisA5 ปีที่แล้ว +1

    Thanks Milan.

  • @betterlifeexe4378
    @betterlifeexe4378 ปีที่แล้ว +2

    I like to use preprocessors for my debug code. I can remove most of my debug code very easy once I'm done making changes. And then like he does I keep the warning and error debug active just by switching my define from "debug_verbose" to "debug_performance".

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว +1

      That's a neat way to do it

    • @betterlifeexe4378
      @betterlifeexe4378 ปีที่แล้ว

      @@MilanJovanovicTech thank you, I also use regions to hide them a little bit better. My editor allows me to collapse the preprocessor section but it's two lines rather than one line with a region. On top of that, my code completion AI has learned that when I type '# Region D...' To finish it with exactly what I want to Debug and closes the region and everything, using the same debug format I use perfectly.

  • @codeme8016
    @codeme8016 ปีที่แล้ว +1

    Thank you so much. Is it OK to have the logs in a database? And how so?

  • @pagorbunov
    @pagorbunov ปีที่แล้ว +2

    I would suggest to add Request ID to logs and make them async configuring WriteTo to be async.

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว

      Serilog is async by design. It logs in-memory to a buffer and then flushes to the file in the background.

  • @ZukoTheShinigami
    @ZukoTheShinigami ปีที่แล้ว +2

    I was hoping you would connect it to a seq sink.
    Is seq usually used in the industry a lot?

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว

      I'd say AppInsights is common with .NET

    • @PaulSpinks
      @PaulSpinks หลายเดือนก่อน +1

      I know it's a old comment but may help someone that comes across this comment. Serilog does have a sink for Seq. It's NuGet package called Serilog.Sinks.Seq. I use Seq at my work it's really handy, we have about 25+ applications feeding into it. I'd also check out meziantou's analyser to prevent incorrect datatypes used. E.g. If your using OrderId and it's an integer and string. If your using OrderId > 10 then the string values that are greater than 10 won't display. However, if you use meziantou's analyser show as warning that it's logging unexpected type. Hope this helps others.

  • @MrAsishMohapatra
    @MrAsishMohapatra 6 วันที่ผ่านมา

    What is the use of using section when we already specifying the write to section? Is it like duplicate things? Why the using section seems to be a namespace?What else can be specified in the using section for the sync?

    • @MilanJovanovicTech
      @MilanJovanovicTech  6 วันที่ผ่านมา

      Docs are always helpful: github.com/serilog/serilog-settings-configuration?tab=readme-ov-file#using-section-and-auto-discovery-of-configuration-assemblies

  • @savithapn1790
    @savithapn1790 ปีที่แล้ว +1

    Great Video, Thank you, i have a question here, i see that you have set the Default loglevel to Information yet in the end of the video we can see in the log.text file debug logs being logged, why is that? Am i missing something here?

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว +1

      I probably left it at Debug while recording that part

  • @nevernerd
    @nevernerd ปีที่แล้ว +2

    This is good but it also feels a bit light. For instance - in a production environment you'd implement masking on sensitive fields. I've tried 3 different libraries and NONE seem to remove the password and ssn correctly - from either the request logging or the global exception handler. For the time being I set that aside because I'm so annoyed with it.

    • @GeoffSeeley
      @GeoffSeeley ปีที่แล้ว +1

      Serilog.Enrichers.Sensitive looks like it does that, but I haven't used it personally. You can also use Filters to exclude an entire matching request.

    • @nevernerd
      @nevernerd ปีที่แล้ว

      @@GeoffSeeley Yup I've used that one. It didn't work so well for me. I mean, at this point either none of these work, or I'm implementing them wrong, or they don't do what I think they do. Should be interesting when I finally find time to drill down into it and find out which.

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว

      I doubt any logging library will take care of that for you.

  • @zaharivaklinov
    @zaharivaklinov ปีที่แล้ว +1

    Thanks for this.
    What about implementing Structured logging, using Serilog without the MediatR library? Do you have any good sources for this?

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว +1

      Just use the ILogger where you think fits

    • @rentefald
      @rentefald ปีที่แล้ว

      What would happen to the logging if MediatR failed?

  • @salmanshafiq8151
    @salmanshafiq8151 ปีที่แล้ว +1

    plz add relative video links in description. If we didn't watch then we can able to watch it.(You said previous video but which video we can't find in description or (i) button.)

  • @johanngodinezquezada8140
    @johanngodinezquezada8140 8 หลายเดือนก่อน

    Hi Milan,
    I came across with this exact configuration you are presenting here, however, I notice the logs are not show in the output window but in the console of the program itself. Looks like there is a specific configuration (Writeto(debug)). My question is, How did you manage to get those logs in the output window with the congiguration shown in this video?, Do you have additional settings in your debug pane from VS?
    Thanks in advance!

    • @MilanJovanovicTech
      @MilanJovanovicTech  8 หลายเดือนก่อน +1

      No idea, really. It just works on my machine 😅 (I didn't do anything special, the logs always showed up in the Output window whenever I run apps)

  • @ammarahmed4140
    @ammarahmed4140 ปีที่แล้ว +2

    hey milan!! its great.. but i need logs to print in seperate folders for each controller. can you please help me out or make another video about serilog with indepth configurations. thanks 👍

  • @sonpham7617
    @sonpham7617 ปีที่แล้ว

    Interesting video. But I noticed your application layer also uses Serilog while installing this package into api layer. How would you be able to do that? Your Application layer also installs Serilog, doesn't it?

  • @jj0904
    @jj0904 6 หลายเดือนก่อน

    Great video as always Milan.
    One question. I want more serious error logs to be written both in the console and in the file, but less important logs like information and events only to the console. How can I do that?

    • @MilanJovanovicTech
      @MilanJovanovicTech  6 หลายเดือนก่อน

      I think you can set a specific LogLevel filter for each sink

    • @jj0904
      @jj0904 6 หลายเดือนก่อน

      @@MilanJovanovicTech Yep found and implemented it. Thank you.

  • @richardaubin1951
    @richardaubin1951 ปีที่แล้ว +1

    How does one enable the highlighting of parameters in VS? I'm using the 2022 community edition.

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว

      This is a ReSharper feature

    • @richardaubin1951
      @richardaubin1951 ปีที่แล้ว

      @@MilanJovanovicTech Thanks. I don't think you mentioned the feature belonging something outside of VS in the video. Either I missed that or the info is missing from the couple of logging videos I did watch. Thanks for the clarification.

  • @jimmuelagwit7032
    @jimmuelagwit7032 ปีที่แล้ว +1

    Hey Milan. What is your VS Theme name?

  • @stevehiggin
    @stevehiggin ปีที่แล้ว +1

    Did you forget to add the enrichers that would have given you the machine name and thread id etc on each log?

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว

      No, they were added from the configuration. For some reason though, they weren't in the log. Strange.

    • @stevehiggin
      @stevehiggin ปีที่แล้ว +1

      @@MilanJovanovicTech you have to add the packages into the project as well as calling them from configuration.
      Install-Package Serilog.Enrichers.Thread
      Install-Package Serilog.Enrichers.Environment

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว +2

      @@stevehiggin Ah that could be it, yeah!

  • @JZO001
    @JZO001 ปีที่แล้ว +3

    Do you have a github example?

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว +3

      I have a blog post about it with examples: www.milanjovanovic.tech/blog/structured-logging-in-asp-net-core-with-serilog

    • @JZO001
      @JZO001 ปีที่แล้ว

      @@MilanJovanovicTech thanks Milan

  • @jezreelfranklin3088
    @jezreelfranklin3088 4 หลายเดือนก่อน

    Where can I find the log file?

    • @MilanJovanovicTech
      @MilanJovanovicTech  4 หลายเดือนก่อน

      You can configure where the output will be

  • @bsalmeida
    @bsalmeida 8 หลายเดือนก่อน

    How can I make the message variables green? 10:52

  • @Carlos-ou2df
    @Carlos-ou2df ปีที่แล้ว +1

    Is the "@" needed?

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว +2

      If you want to deconstruct that argument into JSON, otherwise ToString() will be applied

    • @Carlos-ou2df
      @Carlos-ou2df ปีที่แล้ว

      @@MilanJovanovicTech thanks!! Awesome videos!

  • @dongct2504
    @dongct2504 6 หลายเดือนก่อน

    thank you kind sir.

  • @scorpions3834
    @scorpions3834 ปีที่แล้ว +1

    I have tried to add you on your upword account please consider it