zoukankan      html  css  js  c++  java
  • 记录下XPO生成的SQL语句

    XPO使用了标准的System.Diagnostics的Trace Log机制,只需要在config文件中加入如下代码,即可在Debug时在输出窗口看到XPO生成的SQL语句。

    Config
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        
    <system.diagnostics>
            
    <switches>
                
    <add name="XPO" value="3" />
            
    </switches>
        
    </system.diagnostics>
    </configuration>

    也可以将其记录到日志文件:

    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>

    因为采用.NET标准的Trace Log机制,我们也可以自己实现一个Log类:

    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();
            }
        }
    }

    然后在Config文件中做配置 :

    Config
     <system.diagnostics>
        
    <trace autoflush="true" indentsize="4">
          
    <listeners>
            
    <!--注意命名空间和类名别写错-->
            
    <add name="MyTraceListener" type="Test.MyTraceListener,Test"/>
            
    <remove name="Default" />
          
    </listeners>
        
    </trace>
        
    <switches>
          
    <add name="XPO" value="3" />
        
    </switches>
      
    </system.diagnostics>

    或者在程序的入口点加上:

    // Remove the original default trace listener.
    Trace.Listeners.RemoveAt(0);

    // Create and add a new MyTraceListener.
    Trace.Listeners.Add(new MyTraceListener());

    这样Log内容想记哪儿都可以随自己喜欢了,MyTraceListener的具体实现就不展开了。 

    MSDN: TraceListener 类 

  • 相关阅读:
    CLOSE_WAIT过大,致使tomcat停掉
    nginx安装
    前端知识点及面试题总结
    博客第一次
    二叉树的深度-python
    数字在排序数组中出现的次数-python
    两个链表的第一个公共节点-python
    自动生成接口自动化测试报告
    python实现四舍五入
    使用python的configparser操作.ini配置文件
  • 原文地址:https://www.cnblogs.com/Elvin/p/1664586.html
Copyright © 2011-2022 走看看