Record the SQL statements generated by xpo

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.