Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LoggingBehaviour in the Application project doesn't do anything #1188

Open
Genoe opened this issue May 24, 2024 · 0 comments
Open

LoggingBehaviour in the Application project doesn't do anything #1188

Genoe opened this issue May 24, 2024 · 0 comments

Comments

@Genoe
Copy link

Genoe commented May 24, 2024

Describe the bug
The LoggingBehaviour class and its Process method do execute when a request is made.

To Reproduce
Steps to reproduce the behavior:

  1. Set up a new project. I used the Angular template with SQLite
  2. Set a breakpoint on line 31 in LoggingBehaviour.cs (or anywhere in the Process method)
  3. Do something in the app that fetches data. For example, go to the weather data page.
  4. Observe that the breakpoint was not hit, the app does not log the user and their request

Expected behavior
The breakpoint should be hit and we should log information about the user and their request.

Additional context
Unlike the other behaviors in Application/Common/Behaviours, LoggingBehaviour implements IRequestPreProcessor. According to the Mediatr docs, "RequestPreProcessorBehavior will execute IRequestPreProcessor implementations before any handlers are called". However, the docs also say this "will be registered if in AddMediatR you register any pre/post processors". So it's not clear to me if a step is missing. I'm guessing cfg.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()); in Application/DependencyInjection.cs is supposed to take care of this. But I'm really not sure.

EDIT: Adding cfg.AddRequestPreProcessor(typeof(IRequestPreProcessor<>), typeof(LoggingBehaviour<>)); after cfg.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()); registers LoggingBehaviour and then the breakpoint can be hit. However I'm guessing that is not the intended way for it to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant