IRONSOFTWAREHOME

How to use Custom Logging in C#

Curtis Chau
Curtis Chau
Updated: August 2, 2026

Custom logging in C# allows you to implement a tailored logging system that captures application-specific events and messages. With IronPDF, you can redirect all PDF processing logs to your custom logger by setting LoggingMode to Custom and assigning your logger implementation. This feature enables you to integrate IronPDF's detailed logging output with your existing logging infrastructure, whether you're using NLog, Serilog, log4net, or a custom solution.

Custom logging is valuable when you need to centralize logs from multiple components, apply custom formatting, filter by severity levels, or route logs to specific destinations such as files, databases, or monitoring services. By implementing custom logging with IronPDF, you gain complete control over how PDF generation and processing events are tracked in your application.

Quickstart: Implement Custom Logging with IronPDF

Start with custom logging in C# using IronPDF. This guide shows how to set the LoggingMode to Custom and link it with your logger class. Direct IronPDF messages to your custom logger to monitor and manage application logs. The setup is straightforward and enhances your application's logging capabilities. For a comprehensive overview of IronPDF's features, see our Quickstart Guide.

  1. 1Install IronPDF with NuGet Package Manager

    PM > Install-Package IronPdf

  2. 2Copy and run this code snippet.

    IronSoftware.Logger.LoggingMode = IronSoftware.Logger.LoggingModes.Custom;
    IronSoftware.Logger.CustomLogger = new MyCustomLogger();
    C#
  3. 3Deploy to test on your live environment

    Start using IronPDF in your project today with a free trial
    arrow pointer

How Do I Implement a Custom Logging Example?

To use custom logging, change the LoggingMode property to LoggingModes.Custom. Then assign the CustomLogger property to your custom logger class. This provides flexibility for integrating with various logging frameworks and maintains consistent logging patterns across your application.

The implementation requires minimal setup. Once configured, all IronPDF operations - including HTML to PDF conversion, PDF manipulation, and rendering - automatically send their log messages through your custom logger. This integration ensures you capture critical information about PDF processing operations.

Why Should I Use Custom Logging with IronPDF?

IronSoftware.Logger.LoggingMode = IronSoftware.Logger.LoggingModes.Custom;
IronSoftware.Logger.CustomLogger = new CustomLoggerClass("logging");

IronPDF logs will be directed to the custom logger object. The messages remain identical to those in the IronPDF logger; they are relayed to the custom logger. The custom logger implementation determines how to handle the messages. Consider the following custom logger class example.

Custom logging offers several advantages for production applications:

  • Centralized Log Management: Integrate IronPDF logs with your existing logging infrastructure
  • Enhanced Debugging: Capture detailed information about PDF operations for troubleshooting
  • Performance Monitoring: Track rendering times and resource usage
  • Error Tracking: Automatically capture and report PDF generation failures
  • Compliance: Maintain audit trails for document generation in regulated industries

For applications requiring asynchronous processing, custom logging helps track concurrent PDF operations and identify potential bottlenecks.

What Does a Custom Logger Class Look Like?

public class CustomLoggerClass : ILogger
{
    private readonly string categoryName;

    public CustomLoggerClass(string categoryName)
    {
        this.categoryName = categoryName;
    }

    public IDisposable BeginScope<TState>(TState state)
    {
        return null;
    }

    public bool IsEnabled(LogLevel logLevel)
    {
        return true;
    }

    public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
    {
        if (!IsEnabled(logLevel))
        {
            return;
        }

        // Implement your custom logging logic here.
        string logMessage = formatter(state, exception);

        // You can use 'logLevel', 'eventId', 'categoryName', and 'logMessage' to log the message as needed.
        // For example, you can write it to a file, console, or another destination.

        // Example: Writing to the console
        Console.WriteLine($"[{logLevel}] [{categoryName}] - {logMessage}");
    }
}

This implementation follows the standard Microsoft.Extensions.Logging.ILogger interface, making it compatible with the .NET logging ecosystem. The logger class includes:

  • Category Name: Helps identify the source of log messages
  • Log Level Filtering: Control which severity levels to capture
  • Flexible Output: Route logs to any destination (console, file, database, etc.)
  • Exception Handling: Properly format and log exception details
  • State Management: Support for structured logging with BeginScope

For advanced scenarios, explore rendering options that affect logging output, especially when dealing with complex HTML conversions or when working with the Chrome rendering engine.

How Does Custom Logging Output Look?

In this example, log messages are prefixed with additional information.

Visual Studio debugger console showing IronPDF deployment logs with Chrome client initialization and library loading

The console output demonstrates how custom logging provides detailed insights into IronPDF's internal operations. You can see:

  • Chrome client initialization steps
  • Deployment candidate creation
  • Native library loading sequences
  • Successful component deployment confirmations

This detail level is invaluable when debugging PDF generation issues or optimizing performance. The structured format makes it easy to parse logs programmatically or integrate with log analysis tools.

My favorite library of this kind is IronPDF. It allows for fast and efficient manipulation of PDF files. It also has many valuable features, like exporting to PDF/A format and digitally signing PDF documents.

Milan Jovanovic

Microsoft MVP

View case study

IronOCR means we can save $40,000 annually from manual processing, while enhancing productivity and freeing up resources for high-impact tasks. I would highly recommend it.

Brent Matzelle

Chief Technology Officer, OPYN

View case study

The IronSuite play a crucial role in our operations. These are tools that increase efficiencies across the business including creating floor plans and improving inventory management.

David Jones

Lead Software Engineer, Agorus Build

View case study

Best Practices for Custom Logging Implementation

When implementing custom logging with IronPDF, consider these best practices:

  1. Use Appropriate Log Levels: Configure your logger to capture the right detail level without overwhelming log storage
  2. Include Contextual Information: Add request IDs, user information, or transaction details to correlate PDF operations
  3. Handle Sensitive Data: Ensure your logger doesn't expose confidential information from PDF content
  4. Monitor Performance: Track PDF generation times to identify optimization opportunities
  5. Set Up Alerts: Configure notifications for critical errors or performance degradation

For production deployments, especially when using license keys, proper logging ensures smooth operations and quick issue resolution.

Troubleshooting Common Logging Issues

If you encounter problems with custom logging:

  • Verify your logger implements the ILogger interface correctly
  • Check that LoggingMode is set before any IronPDF operations
  • Ensure your logger is thread-safe for concurrent operations
  • Review log permissions if writing to files or external systems

For additional troubleshooting resources, consult our troubleshooting guide or explore the API Reference for detailed documentation on logging properties and methods.

Ready to see what else you can do? Check out our tutorial page here: Additional Features

Frequently Asked Questions

How do I set up custom logging with IronPDF in C#?

To set up custom logging with IronPDF in C#, configure the `LoggingMode` property to `LoggingModes.Custom` and assign your custom logger to the `CustomLogger` property. This allows you to integrate IronPDF's logging with your existing infrastructure using frameworks like NLog or Serilog.

Why should I use custom logging in IronPDF?

Custom logging in IronPDF offers centralized log management, enhanced debugging, performance monitoring, and error tracking. It provides detailed insights into PDF operations, which is essential for maintaining efficient and compliant applications.

What are the benefits of using custom logging with IronPDF?

Benefits include centralized log management, enhanced debugging capabilities, performance monitoring, error tracking, and compliance with industry regulations by maintaining audit trails for PDF generation.

What must I include in my custom logger class for IronPDF?

Your custom logger class should follow the `ILogger` interface, including methods for setting log levels, outputting messages to destinations like files or databases, and handling exceptions. Add contextual information like request or transaction IDs to enhance logging output.

How can custom logging help with PDF processing issues?

Custom logging provides detailed logs of IronPDF operations, which helps in debugging issues by identifying steps in PDF processing, capturing exceptions, and analyzing rendering times to optimize application performance.

Can IronPDF custom logging work with threads?

Yes, when utilizing custom logging in IronPDF, ensure your logger implementation is thread-safe to handle concurrent PDF operations without data inconsistencies or log corruption.

What is the role of log level filtering in IronPDF's custom logging?

Log level filtering allows you to control which severity levels of logs are captured, enabling you to focus on critical messages while reducing log noise for more efficient log storage management.

How does custom logging integrate with log analysis tools?

IronPDF's custom logging produces structured log entries that can be easily consumed by log analysis tools, aiding in the seamless parsing of logs, performance monitoring, and issue detection across the application.

What are the troubleshooting steps for custom logging issues in IronPDF?

For troubleshooting, verify your logger correctly implements `ILogger`, ensure `LoggingMode` is set before any operations, confirm thread safety, and check permissions if writing logs to external systems.

How does custom logging benefit applications with asynchronous operations?

Custom logging in IronPDF assists asynchronous applications by tracking concurrent operations, identifying bottlenecks, and ensuring log messages are adequately captured and correlated despite execution order.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...
Read More

Ready to Get Started?

Nuget Downloads 20,809,720Version:2026.9just released

Get your FREE

30-day Trial Key instantly.

bullet_checkedNo credit card or account creation required
bullet_testTest in production
without watermarks
bullet_calendar30 days fully
functional product
bullet_support24/5 technical
support during trial
Get your free 30-day Trial Key instantly.
No credit card or account creation required
C# NuGet Library for PDF
Install with NuGet

Version: 2026.9

PM > Install-Package IronPdf
nuget.org/packages/IronPdf/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronPdf"
  3. Select the package and install
C# PDF DLL
Download DLL

Version: 2026.9

or download Windows Installer here.

  1. Download and unzip IronPDF to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronPdf.dll"

Licenses from $999

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required