Xpo uses the standard system. Diagnostics Trace Log Mechanism. You only need to add the following code to the config file to view the SQL statement generated by xpo in the output window during debugging.
Config <? XML version = "1.0" encoding = "UTF-8"?>
<Configuration>
<System. Diagnostics>
<Switches>
<Add name = "xpo" value = "3"/>
</Switches>
</System. Diagnostics>
</Configuration>
You can also record it to a log file:
Config <? XML version = "1.0" encoding = "UTF-8"?>
<Configuration>
<System. Diagnostics>
<Trace autoflush = "true" indentsize = "4">
<Listeners>
<Add name = "logfiletracelistener" type = "system. Diagnostics. textwritertracelistener"
Initializedata = "trace. log"/>
<Remove name = "default"/>
</Listeners>
</Trace>
<Switches>
<Add name = "xpo" value = "3"/>
</Switches>
</System. Diagnostics>
</Configuration>
Because the. NET standard trace log mechanism is adopted, we can also implement a log class by ourselves:
Mytracelistener Using system;
Namespace Test
{
Public class mytracelistener: system. Diagnostics. tracelistener
{
Public mytracelistener ()
{
}
Public mytracelistener (string name)
: Base (name)
{
}
Public override void write (string message)
{
Throw new notimplementedexception ();
}
Public override void writeline (string message)
{
Throw new notimplementedexception ();
}
}
}
Then configure in the config file:
Config <System. Diagnostics>
<Trace autoflush = "true" indentsize = "4">
<Listeners>
<! -- Note that the namespace and class name must not be written incorrectly -->
<Add name = "mytracelistener" type = "test. mytracelistener, test"/>
<Remove name = "default"/>
</Listeners>
</Trace>
<Switches>
<Add name = "xpo" value = "3"/>
</Switches>
</System. Diagnostics>
Or add:
// Remove the original default trace listener.
Trace. listeners. removeat (0 );
// Create and add a new mytracelistener.
Trace. listeners. Add (New mytracelistener ());
In this way, the log content can be remembered wherever you like it. The specific implementation of mytracelistener will not be expanded.
Msdn: tracelistener class