LogWriter File Management

+1 vote
asked Jan 9, 2014 by Tim (390 points)
edited Jan 15, 2014

Is there a programmatic way through the Rebex LogWriter to manage the LogWriter files like rolling logs? Or is this a manual process?

Applies to: Rebex FTP/SSL, Rebex SFTP

2 Answers

+1 vote
answered Jan 10, 2014 by Tomas Knopp (58,890 points)
edited Jan 15, 2014
 
Best answer

Sorry, there is not a built-in support for managing log files. However, you can custom implement the ILogWriter interface and write a RollingLogWriter which you would be able to assign to the LogWriter property of Rebex client objects. Let me know if you need help with this.

commented Jan 10, 2014 by Tim (390 points)
edited Jan 10, 2014

That sounds like a solution. Can you point me to a code example?

commented Jan 15, 2014 by Tomas Knopp (58,890 points)
edited Jan 15, 2014

See this answer for a sample implementation using log4net.

+1 vote
answered Jan 14, 2014 by Tomas Knopp (58,890 points)
edited Oct 10, 2018 by Lukas Matyska

I have implemented a sample Log4NetLogWriter class which internally uses log4net logging capabilities, but at the same time it can be assigned to the LogWriter property of Rebex objects because it implements Rebex.ILogWriter interface. You can download the log4net dll at the project's website. Log4net offers (among others ) a highly customizable log rolling capabilities via the RollingFileAppender class.

Here is the sample which uses the Log4NetLogWriter class. It can be used just the same as Rebex FileLogWriter with one exception. You have to configure the log4net via an app.config.


var client = new Rebex.Net.Imap();

// read the log4net configuration from app.config
log4net.Config.XmlConfigurator.Configure(); // specify the verbose level you want to use
client.LogWriter = new Log4NetLogWriter("Rebex", LogLevel.Debug);

A simple rolling log writer config is available here. Just download the App.config file and put it into the Visual Studio project. The config is for 50KB rolling logs. Maximum number of log files is 100.

...