Skip to content

Logging

Olivier Nizet edited this page Sep 24, 2024 · 3 revisions

If you need to troubleshoot the IO access when downloading the images, you can either provide your own version of HtmlToOpenXml.IO.IWebRequest, either simply providing a ILogger implementation to the DefaultWebRequest.

// 1st parameter is the HttpClient ; null will use the default implementation.
HtmlConverter converter = new HtmlConverter(mainPart, new DefaultWebRequest(null, logger));

Before 2.4 (legacy)

If you need to troubleshoot the conversion, it's possible to capture the silent error messages. This library use the classic tracing mechanism of .Net Framework. You can easily select where to store the log (flat file, xml file, console, ...) If you need further explanation how the tracing API works, you can consult this post on the BCL team blog.

Enable Tracing

In the app.config/web.config, add this snippet:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.diagnostics>
    <sources>
      <source name="html2openxml"
              switchValue="Error">
        <listeners>
          <add name="text" type="System.Diagnostics.TextWriterTraceListener" initializeData="error.log" />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>
</configuration>

Trace Level

The switchValue can have these values:

Error: log any silent errors that occurs such as downloading images or reading base64 images.

Verbose: Error + processed tags