Enable logging with Enterprise Library Logging Application Block

0 votes
asked Aug 31, 2010 by Michael (140 points)
edited Sep 2, 2010

I found an example how to enable logging with Rebex components http://www.rebex.net/kb/logging.aspx

I wonder how would be possible to do the same with using Enterprise Library Logging Application Block?

1 Answer

+1 vote
answered Sep 1, 2010 by Petr (160 points)
edited Sep 2, 2010

Thanks for suggestion. Currently, Rebex does not support using Enterprise Library Logging Application Block directly from its code, since this would require adding reference of Enterprise Library Logging Application Block to our component, thus affecting everyone who uses the component. That does not mean you cannot do it at all, you just have to use custom-defined log writer. In more detail, one should follow these steps:

1. Define your own class implementing the interface Rebex.ILogWriter The most easy way is just deriving from existing class Rebex.LogWriterBase, and overriding ( implementing ) its virtual method WriteMessage(string message).

C#

public class CustomLogWriter : LogWriterBase
{
    public CustomLogWriter()
        : this(LogLevel.Info)
    {
    }

    public CustomLogWriter(LogLevel level)
    {
        Level = level;
    }

    protected override void WriteMessage(string message)
    {
        // Here you will write your own code sending the message 
        // to Enterprise Library Logging.
        // Depending on what you want exactly, you may need to add more methods, 
        // constructors and member variables to achieve your goal.
    }
}

2. Assign the instance of created log writer to the "client"

You can do that similar way as demonstrated in http://www.rebex.net/kb/logging.aspx
Again, the "client" is an instance of Ftp, Sftp, Scp, Smtp, Imap, Pop3, Ssh or Telnet class), and since your CustomLogWriter implements ILogWriter, it can be assigned to LogWriter property.

...