Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
5.2k views
in .NET FTP by (160 points)
Hello, i'm using edtFTPnet free 2.2.1 version.
I would like using its logging system, which seems great, but i'm having trouble with writing log files for more than one ftp connection.
Seems that having more than one class using the Logger, the log entries are "mixed up" among log files.

Example, if i run this code:

FTPConnection ftpconn1 = new FTPConnection();
Logger logger1 = Logger.GetLogger(typeof(FTPConnection));
FTPConnection.LogLevel = LogLevel.Information;
FTPConnection.LogFile = "log1.txt";

logger1.Info("connection 1 info");
logger1.Error("connection 1 error");

FTPConnection ftpconn2 = new FTPConnection();
Logger logger2 = Logger.GetLogger(typeof(FTPConnection));
FTPConnection.LogLevel = LogLevel.Information;
FTPConnection.LogFile = "log2.txt";

logger2.Info("connection 2 info");
logger2.Error("connection 2 error");

Logger.Shutdown();


everything is fine, i got two message per log file.

But when this code is run

FTPConnection ftpconn1 = new FTPConnection();
Logger logger1 = Logger.GetLogger(typeof(FTPConnection));
FTPConnection.LogLevel = LogLevel.Information;
FTPConnection.LogFile = "log1.txt";

FTPConnection ftpconn2 = new FTPConnection();
Logger logger2 = Logger.GetLogger(typeof(FTPConnection));
FTPConnection.LogLevel = LogLevel.Information;
FTPConnection.LogFile = "log2.txt";

logger1.Info("connection 1 info");
logger2.Info("connection 2 info");
logger1.Error("connection 1 error");
logger2.Error("connection 2 error");

Logger.Shutdown();


i got all log entries mixed up... i don't get each connection's message logged into the right log file.
Why such behaviour?
Any ideas?

Thank you,
Marco

4 Answers

0 votes
by (162k points)
It's a static class - you can't send to different files (if they are in different threads there's a property for adding thread ids).
0 votes
by (160 points)
It's a static class - you can't send to different files (if they are in different threads there's a property for adding thread ids).


I cannot find such property in Logger class.. can you give me a hint?
Multithreading could be a solution for me.
Thank you.
0 votes
by (162k points)
You can use Logger.SetTag - this adds a tag for the current thread in the log. Use ClearTag() to clear the current thread's tag.
0 votes
by (200 points)
You can use Logger.SetTag - this adds a tag for the current thread in the log. Use ClearTag() to clear the current thread's tag.


Are there plans to add SetTag and ClearTag to the Pro version? I'm not seeing them in edtFTPnetPRO for .NET 2.0+ v. 7.3.1.20

Categories

...