# Logging Logging when converting documents with GroupDocs.Conversion for .NET To enable logging, use the `ConsoleLogger` class or implement a custom logger via the `ILogger` interface. * The [ILogger](https://reference.groupdocs.com/conversion/net/groupdocs.conversion.logging/ilogger/) interface declares the methods used to perform logging. * The [ConsoleLogger](https://reference.groupdocs.com/conversion/net/groupdocs.conversion.logging/consolelogger/) class implements the methods that output log messages to a standard console. The log contains the following types of messages: * Error - for unrecoverable exceptions * Warning - for recoverable/expected exceptions * Trace - for general information ## Logging to the console To log to a standard console, use the [ConsoleLogger](https://reference.groupdocs.com/conversion/net/groupdocs.conversion.logging/consolelogger/) class implementation: ```csharp using GroupDocs.Conversion; using GroupDocs.Conversion.Logging; using GroupDocs.Conversion.Options.Convert; string documentPath = @"sample.docx"; // NOTE: Put here actual path to your document string outputPath = @"converted.pdf"; // Create console logger ConsoleLogger logger = new ConsoleLogger(); // Create ConverterSettings and specify logger. Func settingsFactory = () => new ConverterSettings { Logger = logger }; using (Converter converter = new Converter(documentPath, settingsFactory)) { PdfConvertOptions convertOptions = new PdfConvertOptions(); converter.Convert(outputPath, convertOptions); } ``` Console output would be as follows: ```console [TRACE] Determine loaded for source document sample.docx ... [TRACE] ... loader selected. [TRACE] Loading source document sample.docx ... [TRACE] ... document loaded. [TRACE] Main document will be converted. [TRACE] Starting conversion of sample.docx... [TRACE] ... pipeline selected ... [TRACE] ... conversion completed. ``` ## Implementing custom logger To log to a file, a stream or any other custom location, implement the [ILogger](https://reference.groupdocs.com/conversion/net/groupdocs.conversion.logging/ilogger/) interface: * For trace messages, implement the `public void Trace(string message)` method. * For warning messages, implement the `public void Warning(string message)` method. * For error messages, implement the `public void Error(string message)` method. The following code snippet shows how to implement a simple file logger: ```csharp using GroupDocs.Conversion; using GroupDocs.Conversion.Logging; using GroupDocs.Conversion.Options.Convert; string documentPath = @"sample.docx"; // NOTE: Put here actual path to your document string outputPath = @"converted.pdf"; // Create logger and specify the output file ILogger logger = new CustomFileLogger("log.txt"); // Create ConverterSettings and specify logger. Func settingsFactory = () => new ConverterSettings { Logger = logger }; using (Converter converter = new Converter(documentPath, settingsFactory)) { PdfConvertOptions convertOptions = new PdfConvertOptions(); converter.Convert(outputPath, convertOptions); } public class CustomFileLogger : ILogger { private readonly string _fileName; /// /// Create logger to file. /// /// Full file name with path public CustomFileLogger(string fileName) { _fileName = fileName; } /// /// Writes trace message to file. /// Trace log messages provide generally useful information about application flow. /// /// The trace message. /// Thrown when is null. public void Trace(string message) { File.AppendAllText(_fileName, $"[TRACE] {message}{Environment.NewLine}"); } /// /// Writes warning message to file. /// Warning log messages provide information about the unexpected and recoverable event in application flow. /// /// The warning message. /// Thrown when is null. public void Warning(string message) { File.AppendAllText(_fileName, $"[WARN] {message}{Environment.NewLine}"); } /// /// Writes an error message to file. /// Error log messages provide information about unrecoverable events in application flow. /// /// The error message. /// The exception. /// Thrown when is null. /// Thrown when is null. public void Error(string message, Exception exception) { File.AppendAllText(_fileName, $"[ERROR] {message}, exception: {exception}{Environment.NewLine}"); } } ``` The content of the `log.txt` file would be as follows: ```console [TRACE] Determine loaded for source document sample.docx ... [TRACE] ... loader selected. [TRACE] Loading source document sample.docx ... [TRACE] ... document loaded. [TRACE] Main document will be converted. [TRACE] Starting conversion of sample.docx... [TRACE] ... pipeline selected ... [TRACE] ... conversion completed. ```