Search code examples
c#pop3openpop

OpenPop : how can I turn off DEBUG printing?


When I use OpenPop.NET lib for draging emails or others, it always shows by console debugging info like:

OpenPOP: (DEBUG) SendCommand: "RETR 84"
OpenPOP: (DEBUG) Server-Response: "+OK message follows"
OpenPOP: (DEBUG) SendCommand: "RETR 85"
OpenPOP: (DEBUG) Server-Response: "+OK message follows"
OpenPOP: (DEBUG) SendCommand: "RETR 86"
OpenPOP: (DEBUG) Server-Response: "+OK message follows"
OpenPOP: (DEBUG) SendCommand: "RETR 87"
OpenPOP: (DEBUG) Server-Response: "+OK message follows"

Can I turn off it?


Solution

  • I know this is an old question but I recently had the same issue and thought I'd share my solution.

    The logging mechanism for OpenPop uses the ILog interface. You can change the default mechanism to use a custom logger by creating a class that implements the ILog interface and then tell OpenPop to use your logger instead by calling the DefaultLogger.SetLog(...) method.

    Now you can do whatever you want with the log information, which includes ignoring it completely.

    See the example:

    // Defines a logger for managing system logging output  
    public interface ILog
    {
        // Logs an error message to the logs
        void LogError(string message);
    
        // Logs a debug message to the logs
        void LogDebug(string message);
    }
    
    public static void ChangeLogging()
    {
        DefaultLogger.SetLog(new MyOwnLogger());
    }
    
    class MyOwnLogger : ILog
    {
        public void LogError(string message)
        {
            Console.WriteLine("ERROR!!!: " + message);
        }
    
        public void LogDebug(string message)
        {
            // Dont want to log debug messages
        }
    }