Want to master Clean Architecture? Go here: bit.ly/3PupkOJ Want to unlock Modular Monoliths? Go here: bit.ly/3SXlzSt
@3m3rs0n Жыл бұрын
It's perfect how you go right to the point and make it easy to understand. Good job Milan!
@MilanJovanovicTech Жыл бұрын
Great, good to know that 😁
@sergiodurval715 Жыл бұрын
Your video helped me a lot I'm studying cqrs with mediator and I intend to use this example log in my project Thanks for sharing knowledge
@MilanJovanovicTech Жыл бұрын
Glad it was helpful!
@ThrottleScotty Жыл бұрын
Excellent video, as usual. I really like the format, succinctness and detail. Keep up the good work Milan!
@MilanJovanovicTech Жыл бұрын
Thank you, it's going to become even better this year
@fernandocalmet Жыл бұрын
Excellent topic, I was just thinking in the last days how to implement logging with Mediatr. Thank you very much Milan
@MilanJovanovicTech Жыл бұрын
There you go! 😁
@nove1398 Жыл бұрын
Great video. Similar approach to making exception handling.
@MilanJovanovicTech Жыл бұрын
Right! Middleware solves many problems
@vu5700 Жыл бұрын
Amazing video sir, i really enjoy your videos , very concise and and concrete, keep it up!
@MilanJovanovicTech Жыл бұрын
Thank you very much!
@Adronius Жыл бұрын
I really enjoy your videos! Short, to the point, with great value. It would be great to see the repository. I'd like to learn more on the Result implementation and how the other MediatR classes looks like. Like for example the UpdateProductCommand. Btw, get also some free time, so that you don't burn out. Working on Christmas day is not a good idea ;-)
@MilanJovanovicTech Жыл бұрын
I covered most of these in some of the previous videos - UpdateProductCommand -> Minimal API Organization - Result -> Validation from Aug/Sep - Repository -> Repository Pattern video
@kwwx345 Жыл бұрын
It would be nice to see you make a video on other ways to manage cross cutting concerns like aspect oriented programming with postsharp(or new metalama) or other similar tools.
@MilanJovanovicTech Жыл бұрын
Very interesting, I'll have to add this to my content list! 😁
@thomaswoods13654 ай бұрын
Really nice Milan. Thank you!
@MilanJovanovicTech4 ай бұрын
Most welcome
@richardhaughton9633 Жыл бұрын
Great video again! Could you please make one on logging with ELK stack (Elastic search, LogStash and Kibana) ?
@MilanJovanovicTech Жыл бұрын
Absolutely! I want to cover all the hot topics, but I want to make the videos easy to consume (short) so I can't tackle everything in one video.
@oyedeoluwafunbi9635 Жыл бұрын
@@MilanJovanovicTech I am totally looking forward to this!!
@bugadada Жыл бұрын
Much respect for what you do, keep going!
@MilanJovanovicTech Жыл бұрын
I appreciate that!
@MarcusKaseder Жыл бұрын
Why do you add an @ in front of your placeholders? One thing to mention for logging in general: Even if the logs are disabled by config, the cost is still there. If we assume that DateTime.UtcNow will take 1 second to execute, it will also take one second when the log level is disabled. There are some workarounds to avoid this. One is a delegate that only executes if the log level is enabled. Another one is to nest your log into a if that checks the log level and only executes if log level is enabled. Wanted to mention that because some traces can be cost intensive. That traces are mostly not required in production mode.
@MilanJovanovicTech Жыл бұрын
Just a convention I saw somewhere with "@", but it seems it's not even needed. Great point about the cost of non-logged logs, I'll have to bring this up in a future video!
@MarcusKaseder Жыл бұрын
@@MilanJovanovicTech Ah, okay. Wondered if I missed something. It's always about personal preferences 😉 Since those placeholders are reflected by structured logging in JSON or logging targets (logging DBs), it personally feels strange to me to query for @ItemId = 1 instead of ItemId = 1. Great Video as always 🙂
@MilanJovanovicTech Жыл бұрын
@@MarcusKaseder From my testing, they are excluded in logs. At least with Serilog
@dariogriffo Жыл бұрын
Marcus, the @ is identified in "THE" best structured logging library: Serilog as the way to render an object as JSON in your log properties. My suggestion is DONT use Microsoft logging, but use Serilog directly. Microsoft is an abstraction an misses a lot of what you can do with the vendor specific.
@MarcusKaseder Жыл бұрын
@@MilanJovanovicTech @Darío Found the following: The @ symbol before the segment argument is a part of the Message Template specification which means that Serilog must expand the argument's structure as an object. Without this symbol Serilog would just log the result of segment.ToString(). Segment is a class I that case.
@zikkrype Жыл бұрын
Nice one. For me the biggest problem is always splitting LogEvent ID between different application layers (e.g: new EventId(100, "Unhandled"), new EventId(1001, "Payments"))
@MilanJovanovicTech Жыл бұрын
I think that can be handled very nicely by Serilog's LogContext
@zikkrype Жыл бұрын
@@MilanJovanovicTech that's not what i'm talking about. later you filter your logs in kibana or application insights using event(id, name). How to avoid collisions of ids etc
@syedemad1070Ай бұрын
In vsa will conventional middleware for logging work with mediatr?
@MilanJovanovicTechАй бұрын
Yes
@shirinmonzavi81658 ай бұрын
Hi How to extract information about what handler is handled the request?
@MilanJovanovicTech8 ай бұрын
I'm guessing the RequestHandlerDelegate should have that info somewhere
@ransandu Жыл бұрын
Hi Milan, Thanks for this. Small clarification. The implementation you did is only covering all the inbound request/response. How about logging outbound request/response. E.g Assume we calling a 3rd party application. Want to record what we send and receive in our logs. Any thought on this?
@MilanJovanovicTech Жыл бұрын
If you're calling that API via HttpClient, you can create a delegating handle and introduce the logging in there
@abdulatifrasulov72918 ай бұрын
Good job. But i have one question. Is this behavior effect API performance if this API should serve large number of requests?
@MilanJovanovicTech8 ай бұрын
Logging will incur a performance penalty, but not knowing what your app is doing is a bigger problem.
@ederjuniordesouza1618 Жыл бұрын
Hello Milan great video, thank you for sharing :) I was expecting to see something about MediatR, is it coming in a next video or did I miss something in this video ?
@MilanJovanovicTech Жыл бұрын
Check out this maybe: kzbin.info/www/bejne/rJXMXqNviNmgfZI
@MilanJovanovicTech Жыл бұрын
Also, validation with MediatR: kzbin.info/www/bejne/bmbHqaqaba2te80
@volodymyrliashenko1024 Жыл бұрын
I was expecting to see structure logs as a result and than how to use it and what the benefits of having Structured Logs vs plain logs.
@MilanJovanovicTech Жыл бұрын
I'm planning that for the Serilog video which is coming soon
@volodymyrliashenko1024 Жыл бұрын
@@MilanJovanovicTech Would be nice if you can recommend application for viewing structured logs locally.
@fahimehbarzegar5322 Жыл бұрын
Is it just about log in application layer? How can we use this approach to log infrastructure layer, such as repository? Or what is the best way to log them?
@MilanJovanovicTech Жыл бұрын
You can add a decorator to your repositories, or log within command handlers if you feel you need go
@BaffourKTonto Жыл бұрын
Is Logging the same as having auditing to keep information about which user performed an operation?
@MilanJovanovicTech Жыл бұрын
They serve a different purpose. Auditing is storing data for historical reference. Logs are usually short-lived and are only relevant for a few days.
@murilomurilo3930 Жыл бұрын
Where the connection string is stored? I like your videos! ❤
@MilanJovanovicTech Жыл бұрын
Appsettings.json
@alpsavasdev7 ай бұрын
what are the disadvantages of logging in application layer, compared to in API layer (in controller methods)?
@MilanJovanovicTech6 ай бұрын
You can do both
@ManojRawat-lp4yc2 ай бұрын
Is it a good practice to create this pipeline behavior handling class for every .NET core project where we need to log information and errors ? Or is it something specific to MediatR only ? Like if I want to do this for Serilog DB log sinking ? Will it be good design ? Edit ** After going through the Video one more time** I think we can use it anywhere not just with MediatR. But if possible please confirm. Thank You.
@MilanJovanovicTech2 ай бұрын
Pipeline behavior is a MediatR feature. You could implement a middleware if you need this in Web apps.
@vinland-h1w Жыл бұрын
I'm using NLog and I'm confused, It's already in the API project, should I do the same in Application layer? Also, how can this affect the flow if I have validatorsbehavior too. I hope u can respond thanks a lot!
@MilanJovanovicTech Жыл бұрын
I think it's fine to keep it in the Application layer.
@vinland-h1w Жыл бұрын
@@MilanJovanovicTech thank you so much, this helps a lot
@sauravbhatta5303 Жыл бұрын
Precise info
@MilanJovanovicTech Жыл бұрын
Thank you!
@ahsanmehmoodqureshi7035 Жыл бұрын
please tell the model domain.shared =Result .which fields inside in it
Yo Milan. Thanks for video. I can't enter into Handle method of logging pipeline. Any thoughts? Here's my implementation (i'm using FluentResults): public class LoggingPipelineBehavior : IPipelineBehavior where TRequest : IRequest where TResponse : Result public class CategoryQueryHandler : IRequestHandler, IRequestHandler
@MilanJovanovicTech7 ай бұрын
The problem is: where TResponse : Result Try out with just Result (if it exists) or an interface
@winstochurgle91337 ай бұрын
@@MilanJovanovicTech Well i tried like this: public class LoggingPipelineBehavior : IPipelineBehavior where TRequest : IRequest where TResponse : IResultBase Because Result inherits IResultBase and it's worked. Thanks!
@aslanamca8225 Жыл бұрын
I see cqrs and mediatR even when I want to learn another subject. I hate this situation.
@MilanJovanovicTech Жыл бұрын
If you can't beat them, join them?
@gerarduab9960 Жыл бұрын
Thanks. But how to read logs in production environment during certain period of time?
@MilanJovanovicTech Жыл бұрын
Where's your production environment?
@krccmsitp2884 Жыл бұрын
In production you would store the logging messages in a centralized logging store, e.g. Seq, Logstash, SolarWind, or a cloud storage system.
@pbolduc Жыл бұрын
@@krccmsitp2884 We use Splunk via Serilog. But I understand what Gerard is asking. For example, a user is reporting an error, but the existing log levels are not verbose enough. It would be useful to be able to turn on more detail logging for a period of time. Previously with trace listeners, you configure your trace listener with a trace switch. You could programmatically at run time change the trace level. You could have an administrative endpoint that you could call to change the level to Verbose (Debug in .NET Core ILogger), and start a timer to reset the level to Information after a short period of time like 5 minutes. I also have use case where I would like to enable logging for one or more users. Although both of these situations do not work well if you are running multiple instances such as on Kubernetes.
@gerarduab9960 Жыл бұрын
@@pbolduc that's. Always I listen to add ilogger to logging user data, errors, but who I turn that in order to make it more practice. I think that this data should save it in some kind of log store but during certain periods of time, also this data should be filtered in order to extract metrics. My question it's that, what infrastructures, approach are used in production environments.
@CyborgT800 Жыл бұрын
Can you cover Microsoft App insights logging
@MilanJovanovicTech Жыл бұрын
Good idea! I'll add it to my queue
@10Totti Жыл бұрын
Thanks code is on github?
@MilanJovanovicTech Жыл бұрын
www.patreon.com/milanjovanovic
@rubenguinez92 Жыл бұрын
I tested this and the content of class LogginPipelineBehavior is not triggered. I really don't know what happened. Of course I've set up DI and the packages installed. (NET 7)
@MilanJovanovicTech Жыл бұрын
Did you setup the pipeline with MediatR?
@rubenguinez92 Жыл бұрын
@@MilanJovanovicTech AddMediatr and IPipelineBehavior registered in services/Program.cs, just like you do in the video…
@rubenguinez92 Жыл бұрын
@@MilanJovanovicTech In the video, do you use net 7?
@MilanJovanovicTech Жыл бұрын
@@rubenguinez92 Yes
@MateStier-hd4nv9 ай бұрын
I would like to log Result.Value, wow can i implement it?:D
@MateStier-hd4nv9 ай бұрын
I Can with reflection, but not nice PropertyInfo? valueProperty = result.GetType().GetProperty("Value"); object? propValue = valueProperty?.GetValue(result, null); _logger.LogInformation( "Handle Complited {@RequestName}, {@value}", reuqestType.Name, propValue);
@MateStier-hd4nv9 ай бұрын
I would like to make it type safety! Is it possible?:D
@MilanJovanovicTech9 ай бұрын
Why not simply log... Result.Value - what's preventing you?
@MateStier-hd4nv9 ай бұрын
@@MilanJovanovicTech When add constrain: public class LoggingPipelineBehavior : IPipelineBehavior where TRequest : IRequest where TResponse : Result Mediatr dont use it. I take breakpoint this class , but dont stop -> dont use it. Only use when i use just where TResponse : Result. i want to use Result implementation
@Maorprog Жыл бұрын
Great tutorial. can you please share with us the code in github? Thanks!
@MilanJovanovicTech Жыл бұрын
I only share the code with my Patreon supporters
@Alexandrplayable Жыл бұрын
How to write this if my Result class write how Result??? help meee