Table of contents
Benefits of Action Filter Logging in Umbraco#
Integrating action filters for logging in Umbraco offers multiple advantages:
- Effortless Integration: Add robust logging with minimal effort.
- Granular Control: Apply filters globally or to specific API endpoints.
- Performance-Friendly: Non-blocking, asynchronous operations ensure your application remains responsive.
These benefits make custom action filters a go-to solution for API logging in Umbraco.
Step 1: Crafting the Custom Logging Filter#
Start by creating a new class, UmbracoCustomLoggingAttribute, that inherits from ActionFilterAttribute.
The key method is OnActionExecutedAsync, which allows access to the HttpActionExecutedContext object, including the Exception property.
Here’s how to implement it:
Pro Tip: Use meaningful log messages to make troubleshooting faster.
Step 2: Integrating the Filter#
Now that your custom filter is ready, it’s time to apply it.
Depending on your needs, you can annotate an entire UmbracoApiController or specific endpoints.
Example: Annotating a Controller
This flexible approach lets you decide where logging should occur - globally for consistency or selectively for optimization.
Step 3: Optimizing Your Logging Configuration#
Logging can be a double-edged sword.
While detailed logs are invaluable in development, excessive logging in production can impact performance.
Adjusting Logging Levels in Umbraco 8
Umbraco 8 uses Serilog, a powerful and customizable logging library.
Here’s how to configure it:
- Go to the \config directory in your project.
- Open the serilog.config file.
- Locate the <appSettings> section.
- Set serilog:minimum-level to Error to capture only critical logs.
Why “Error” Level?
Logging only errors reduces clutter, making it easier to spot critical issues in production.
Conclusion#
Effective error logging is the backbone of a smooth user experience.
Implementing custom action filters and configuring optimal logging levels can ensure efficient debugging and stable performance for your Umbraco API.
Ready to take your Umbraco expertise to the next level?
Explore More: Visit our blog for additional insights into maximizing Umbraco's potential.
Need Help? Contact us for tailored support with your Umbraco projects.