Skip to footer content

How to use Custom Logging in C#

In this tutorial, we explore how to implement custom logging in C# applications using IronPDF. First, ensure IronPDF is installed via the NuGet Package Manager.

Start by configuring IronPDF to use custom logging by setting the logging mode of the IronSoftware.Logger to custom. Instantiate a custom logger class and assign it to the custom logger property. This custom logger class implements the ILogger interface from Microsoft.Extensions.Logging. The constructor requires a category name parameter, and the BeginScope method returns null, as scope functionality is not needed here. The IsEnabled method always returns true, ensuring logging is active at all log levels. The core logic resides in the Log method, which processes parameters like log level, event ID, state, exception, and formatter. This method can be customized to direct logs to various destinations, such as files or databases.

After setting up the custom logging, render a PDF from a URL using IronPDF to view log details. The generated log provides insights into PDF generation processes, including progress, errors, warnings, and performance metrics.

By following these steps, you can effectively implement custom logging in your C# applications using IronPDF. Don't forget to subscribe for more tutorials from Iron Software and try IronPDF by signing up for a trial on their website. Experience the software's capabilities firsthand by downloading and installing the package.

Further Reading: How to use Custom Logging in C#

Chipego
Software Engineer
Chipego has a natural skill for listening that helps him to comprehend customer issues, and offer intelligent solutions. He joined the Iron Software team in 2023, after studying a Bachelor of Science in Information Technology. IronPDF and IronOCR are the two products Chipego has been focusing on, but his knowledge of all products is growing daily, as he finds new ways to support customers. He enjoys how collaborative life is at Iron Software, with team members from across the company bringing their varied experience to contribute to effective, innovative solutions. When Chipego is away from his desk, he can often be found enjoying a good book or playing football.