Subject: using  ComponentPro.Diagnostics.XTrace
Date: 2020-12-24 15:03:03
From: nicis
Source: using-componentpro-diagnostics-xtrace
----------------------------------------------------------------------

Hi,

I want to activate xtrace log when I'm using ftp & sftp tools but on a specific way :

dynamically, I can open 1 or more connections.
when I open several connections at the same time, I want, for each connection ,  that the logs be recorded in one different file.
(1 ftp session = 1 log file). each log will contain only logs related to "his associated connection"

I created my own custom class . the philosophy is the following :

public class MyCustomLog : ComponentPro.Diagnostics.UltimateTextWriterTraceListener
{
public String TraceFileName = null;
public TextWriter _LogAppSession = null;

public override void TraceData(object source, TraceEventType eventType, string category, string message)
{
     this._LogAppSession.WriteLine("--->"   message);
}

public int Init (String LogFile)
{
	TraceFileName = LogFile;
	if (File.Exists(this.TraceFileName) == false )
	{
	   this._LogAppSession = TraceFileName.CreateText(false );
	else 
	   this._LogAppSession = TraceFileName.AppendText(false );
}


when I create the class for each ftp connnection :

c_session_ftp = new ComponentPro.Net.Ftp();
logListner = new MyCustomLog ();

logListner.Init (session_log);

ComponentPro.Diagnostics.XTrace.Default.Level = ComponentPro.Diagnostics.TraceEventType.Verbose;
ComponentPro.Diagnostics.XTrace.Default.Listeners.Add(session.logListner);


but this does not work as I expected, the _LogAppSession is null

an alternative was to use a static class and detect within tracedata the correct connection/log file
i wanted to use the source value to detect the "related" connection
but, until the "ftp" connection is "opened", the source value is null. 


how can be such a behavious (1 log file per connection ) be implemented ?

many thanks for your help

----------------------------------------------------------------------

Note: This question has been asked on the Q&A forum of Thang Dang's fraudulent ComponentPro brand
If you purchased anything from ComponentPro, you have been scammed. Contact the payment processor
who sold you the license and ask for your money back.

Back to ComponentPro Q&A Forum Index