Logging the data in Trace.axd to a text/xml file

后端 未结 2 1056
闹比i
闹比i 2021-01-20 15:20

In trying to track down a performance issue that is only occurring in our production environment, we have enabled tracing within the app so see method calls and page load ti

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-20 15:57

    The trace data is under cover a standard DataSet. You can't get a hold on it officially, but here is a hack that can do it (it seems to work on .NET 2 to 4):

    public static DataSet GetTraceData(Page page)
    {
        if (page == null)
            throw new ArgumentNullException("page");
    
        return (DataSet)typeof(TraceContext).GetField("_requestData",
               BindingFlags.NonPublic | BindingFlags.Instance).GetValue(page.Trace);
    }
    

    Once you have the DataSet, you can do anything you want with it, save to an XML file (DataSet.WriteXml), a stream, etc.

    Of course, since it uses an internal field, it may not be supported in the future.

提交回复
热议问题