7 Serilog Best Practices for Better Structured Logging

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

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

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

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

  • @VladyslavHorbachov
    @VladyslavHorbachov 9 месяцев назад +6

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

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

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

  • @AndyMacConnell
    @AndyMacConnell 9 месяцев назад +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 9 месяцев назад +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!

  • @EHBRod13
    @EHBRod13 9 месяцев назад +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  9 месяцев назад

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

  • @prathameshshende4
    @prathameshshende4 9 месяцев назад +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  9 месяцев назад +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 9 месяцев назад

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

  • @VintunaSayami
    @VintunaSayami 9 месяцев назад +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  9 месяцев назад +1

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

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

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

  • @drhdev
    @drhdev 9 месяцев назад +3

    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 9 месяцев назад +2

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

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

    Love your all videos.. ❤

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

    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!

  • @PelFox
    @PelFox 9 месяцев назад +2

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

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

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

  • @dotnetMasterCSharp
    @dotnetMasterCSharp 2 дня назад

    This is awesome and useful video

  • @porcinetdu6944
    @porcinetdu6944 9 месяцев назад +2

    The video is really great

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

      Glad you enjoyed it, I love sharing practical tips

  • @mahmoudalaskalany
    @mahmoudalaskalany 9 месяцев назад +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  9 месяцев назад +1

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

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

    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  9 месяцев назад

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

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

    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  2 месяца назад +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 2 месяца назад

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

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

    Great content as always. Thank you!

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

    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  9 месяцев назад

      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.

  • @InshuMussu
    @InshuMussu 9 месяцев назад +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

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

    Great! Thanks!

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

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

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

      Yes (but include a Trace to know which service its from)

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

      @@MilanJovanovicTech Ok, thanks

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

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

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

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

  • @alukardishe
    @alukardishe 9 месяцев назад +2

    awsome dude

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

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

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

    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  9 месяцев назад +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

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

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

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

      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

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

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

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

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

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

    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  9 месяцев назад

      They'll be lost, yes

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

      @@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.

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

    What was the Result object in the pipeline behavior?

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

      gist.github.com/m-jovanovic/aa25b1ae424c985ff8ae696a79b6fe6e

  • @리오날정
    @리오날정 9 месяцев назад

    Great Thanks~~👍

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

    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 ?

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

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

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

      If it has a lot of stars on github, yes

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

      This one? github.com/stevejgordon/CorrelationId

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

    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  8 месяцев назад

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

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

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

  • @VHMate
    @VHMate 9 месяцев назад +5

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

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

    What about application insights?

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

    Can we get the source code of this..

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

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

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

    Actually, you forgot to await next in the middleware.

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

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

    • @yurii1111
      @yurii1111 9 месяцев назад +2

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

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

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

  • @sunzhang-d9v
    @sunzhang-d9v 9 месяцев назад +1

    expect Hangfire