7 Serilog Best Practices for Better Structured Logging

Поделиться
HTML-код
  • Опубликовано: 17 янв 2025

Комментарии • 92

  • @MilanJovanovicTech
    @MilanJovanovicTech  Год назад +3

    Want to master Clean Architecture? Go here: bit.ly/3PupkOJ
    Want to unlock Modular Monoliths? Go here: bit.ly/3SXlzSt

  • @VladyslavHorbachov
    @VladyslavHorbachov Год назад +7

    This is one of the best videos on your channel. No water, only good explanation and example. Keep doing like this!

    • @MilanJovanovicTech
      @MilanJovanovicTech  Год назад +3

      Glad you liked it! Working on upping the content quality :)

  • @AndyMacConnell
    @AndyMacConnell Год назад +1

    Awesome as always Milan! Thanks for continuing to produce top quality content. I look forward to giving this and Seq a go in future applications I write.

  • @rexlatinae3439
    @rexlatinae3439 Год назад +2

    I must say that you are, in my opinion, the best software developer youtuber and not just in terms of .NET but in general. The way you structure your content, I haven't found that structure anywhere else. From long type videos to short videos and all the way to community, you provide knowledge on every day basis and you are always ready to respond to community that follows your work. Good job, wishing you all the best in the future and can't thank you enough!

  • @InshuMussu
    @InshuMussu 11 месяцев назад +1

    Love your all videos.. ❤

  • @drhdev
    @drhdev Год назад +4

    Can you go over deep diving logs with Azure Application Insights/Azure Log Analytics/Azure Monitor as well as exporting logs?

  • @MuhammadYasir-cx5ng
    @MuhammadYasir-cx5ng Год назад +2

    Can you please make a video on Grafana and make some comparison with Seg...

  • @porcinetdu6944
    @porcinetdu6944 Год назад +2

    The video is really great

  • @dotnetMasterCSharp
    @dotnetMasterCSharp 2 месяца назад

    This is awesome and useful video

  • @vadimr5847
    @vadimr5847 Год назад

    Great content as always. Thank you!

  • @EHBRod13
    @EHBRod13 11 месяцев назад +2

    Milan! You're mentioned on page 227 of Apps and Services with .NET 8 by Mark J. Price in the Serilog section! I was reading that to supplement this video.

    • @MilanJovanovicTech
      @MilanJovanovicTech  11 месяцев назад

      So cool! Thanks for letting me know. 😁 I actually have a copy of the book, but I missed this.

  • @VintunaSayami
    @VintunaSayami Год назад +2

    Log volume continues to grow over time. Seq can handle the substantial log data?? Are there specific considerations or best practices that need to be taken into account when implementing Seq?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Год назад +1

      Seq can handle it. But you can also configure log lifetime to X days, for example.

    • @MilanJovanovicTech
      @MilanJovanovicTech  4 месяца назад +1

      You'd typically delete the log data after some retention period. Or you can move it into some cold storage.

  • @PelFox
    @PelFox Год назад +2

    Would you still recommend using Serilog of you only use application insights?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Год назад

      You can still use Serilog + App Insights sink? I did that setup on one project
      Or just use App Insights on its own

  • @araneoadrian
    @araneoadrian Год назад +1

    Great! Thanks!

  • @리오날정
    @리오날정 Год назад

    Great Thanks~~👍

  • @prathameshshende4
    @prathameshshende4 Год назад +1

    Hi milan, I have gone almost all your videos regarding architecture and patterns. I really like your videos. I m insist you to create videos series on authorization and authentication. Cookie, JWT and even with SSO and OpenId Connect without using any third party libraries apart from Microsoft itself.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Год назад +1

      - JWT - ruclips.net/video/4cFhYUK8wnc/видео.html
      - JWT + Firebase - ruclips.net/video/xBuLWaDcvu0/видео.html
      - Permission auth - ruclips.net/video/PlbAuNvR16s/видео.html [4 part series]

    • @prathameshshende4
      @prathameshshende4 Год назад

      @@MilanJovanovicTech hope you will add some videos about sso login with openid like identity server 4 but not using identity server.

  • @mahmoudalaskalany
    @mahmoudalaskalany Год назад +1

    that is great video , can i use the same structuring of LogContext in azure application insights and make the search easy like this , because am suffering when searching and logging to application insights and it cost a lot of RUs

    • @MilanJovanovicTech
      @MilanJovanovicTech  Год назад +1

      Yes, you can. Although App Insights should already support structured logging.

  • @alukardishe
    @alukardishe Год назад +2

    awsome dude

  • @theprantadutta
    @theprantadutta Год назад +1

    Can I use only one seq docker instance with multiple Dotnet Api projects?

  • @omarmet9584
    @omarmet9584 4 месяца назад

    Great video
    i'm currently looking to implement logging in a project with the same structure as the project in this video with the result pattern.
    so far it would be good but how would i deal with unexpected exception
    i have the expected part handled with the result pattern like calling the saveChangesAsync, i wrapped it inside a result "still not sure if it is a good idea",
    but for the unexpected part i'm thinking i would have a try and catch wrapping the request in the middle but i don't think it's a good idea to have logging separated into two places.
    i would love to hear what do you think of this situation

    • @MilanJovanovicTech
      @MilanJovanovicTech  4 месяца назад +1

      You can create a global exception handling middleware for unhandled exceptions. You can log the error there, and return some response to the user.

    • @omarmet9584
      @omarmet9584 4 месяца назад

      i am going to look into it and thanks for the fast response and your videos helped me a lot

  • @z070z
    @z070z 9 месяцев назад

    Dear Milan, Thanks a lot for your comprehensive videos.
    Is SEQ recommended for production or maybe using ELK stack? Can I integrate health check with SEQ ?
    Thank you!

  • @aygtx8869
    @aygtx8869 Год назад

    Thanks for the video, Milan,
    can I use Serilog throughout all the 4 Clean Architecture layers without violating its principles and without having to install the package again?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Год назад

      You will very rarely need logging in Domain layer, but I don't see using ILogger a big issue

  • @LeotrimJusufi
    @LeotrimJusufi Год назад

    Hello Milan! Great video! Posted a comment on one of your previous videos. Pasting it here as well:
    “An off topic question regardin DDD and Ef Core tracking. In a classic repository pattern approach you for instance have a update method which you call upon. But is that necessary in DDD? For instance lets say i have a BasketEntity with a list of ProductEntities. If I add a product to the basket I simply call the entity method "AddProductToBasket" and just call "SaveChangesAsync" method from unit of work in the handler, and create the new line in the Db. Is this a valid approach? Because in that case - u never have to include/use the update method since Ef Core tracks the changes.”
    Thanks in advance!

    • @MilanJovanovicTech
      @MilanJovanovicTech  Год назад

      You don't. If you want to be purist you can use the Update method on a repo. In some cases, you'll simply need to have it to make it work with EF. As always, be pragmatic and do what works for you.

  • @bloopers2967
    @bloopers2967 4 месяца назад

    Is there something like enrichers in Microsoft.Extensions.logging framework?

    • @MilanJovanovicTech
      @MilanJovanovicTech  4 месяца назад

      There's Scopes. You could create a scope from a middleware or MediatR pipeline and it would apply for all logs within: learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.logging.loggerextensions.beginscope?view=net-8.0

  • @InshuMussu
    @InshuMussu 11 месяцев назад +1

    I have been using serilogs, mediator, middlewares etc. But i couldn't catch this idea. how did you get this.. could you plz give some tips.. thanks

  • @hbenvenutti
    @hbenvenutti 10 месяцев назад

    What was the Result object in the pipeline behavior?

    • @MilanJovanovicTech
      @MilanJovanovicTech  10 месяцев назад

      gist.github.com/m-jovanovic/aa25b1ae424c985ff8ae696a79b6fe6e

  • @alekseygrachev4025
    @alekseygrachev4025 Год назад

    Thanks! What is the best way to configure log settings in an Azure function? There's no appsettings by default.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Год назад +1

      But there is a similar settings JSON file, from what I can recall 🤔
      Either way, you just want to set ENV vars

  • @ahmedrizk106
    @ahmedrizk106 Год назад

    I noticed there is already a 'RequestId' property attached to the request logs which is the same property as the correlation Id. do we need the correlation id or we can just use the request Id ?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Год назад +1

      The value is the same, yes. That's the TraceIdentifier. However, if you want to share this across services it's better to use a custom structured log property

  • @MichalPaukert
    @MichalPaukert Год назад

    There is already nuget package for correlation id. Should I use this insead?

    • @Kasiux
      @Kasiux Год назад

      If it has a lot of stars on github, yes

    • @MilanJovanovicTech
      @MilanJovanovicTech  Год назад

      This one? github.com/stevejgordon/CorrelationId

  • @adnenbenawicha5082
    @adnenbenawicha5082 8 месяцев назад

    is it possible to use serilog with MultiTenancy, because i want to log to diffrent database depending the scope of the request ?

  • @janjoska2549
    @janjoska2549 Год назад

    Do you use logger scopes? I think they are ultra-cool. using (logger.BeginScope(new {OrderNumber = order.Number})) etc

    • @MilanJovanovicTech
      @MilanJovanovicTech  Год назад

      Scopes are the same idea as the LogContext I used in this video

  • @TheAzerue
    @TheAzerue Год назад

    If we use Warning for production, and later in time we need to see logs with Level "Information". Won't those logs be lost since SeriLog was skipping info logs in production ?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Год назад

      They'll be lost, yes

    • @TheAzerue
      @TheAzerue Год назад

      @@MilanJovanovicTech So isn't it safe to use level as "Information" in production as well instead of "Warning", in case we want to find or track a scenario.

  • @juraj4326
    @juraj4326 Год назад

    Hello! And what about distributed logs ? From where context.TraceIdentifier is coming from and how to pass this value to other requests (if i'm accessing some API with HttpClient). I mean whether it is still necessary to use CorrelationId in http headers. And can u maybe explain difference beween TraceId from serilog, context.TraceIdentifier and RequestId from Serilog ?

  • @EvekoShadow
    @EvekoShadow 8 месяцев назад

    What about application insights?

  • @zohibshaikh2832
    @zohibshaikh2832 9 месяцев назад +1

    Can we get the source code of this..

    • @MilanJovanovicTech
      @MilanJovanovicTech  9 месяцев назад

      On Patreon, or here: www.milanjovanovic.tech/blog/5-serilog-best-practices-for-better-structured-logging

  • @YasSin
    @YasSin Год назад

    Great. I have the same color sweatshirt wich you can see in my profile picture as well 😂

  • @yurii1111
    @yurii1111 Год назад

    Actually, you forgot to await next in the middleware.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Год назад

      Nope, don't need to await - I can just return the task. And the previous step in the middleware will await it.

    • @yurii1111
      @yurii1111 Год назад +2

      ​@@MilanJovanovicTechyes. but using scope can call dispose immediately. Technically you have introduced a race condition here.

    • @dy0mber847
      @dy0mber847 8 месяцев назад

      ​@@yurii1111why is it dangerous? What could happen here? Explain, please

  • @VHMate
    @VHMate Год назад +5

    Pls add git repo, because it's unfollowable... :(

  • @SalmanShafiq-y3q
    @SalmanShafiq-y3q 10 месяцев назад

    Without water it 's crystal clear 😊
    I need your help plz.
    your Result pattern was a real cream. i didn't miss your any video for last year.
    I did the following things for strong type return but it does not generate schema in Open API.
    public async Task Login(
    ISender sender,
    LoginRequestCommand command)
    {
    Result? result = await sender.Send(command);
    return result.Match(
    onSucceed: () => Results.Ok(result),
    onFailed: result.ToProblemDetails);
    }

    • @MilanJovanovicTech
      @MilanJovanovicTech  10 месяцев назад

      You'll have to figure out how to make TypedResults work for that. Or decorate the endpoint with descriptions on return types.

  • @sunzhang-d9v
    @sunzhang-d9v Год назад +1

    expect Hangfire