October 21, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

ADO.NET Trace Logging

  • January 22, 2008
  • By Bipin Joshi
  • Send Email »
  • More Articles »

Reading the Trace

Now that you have logged some trace information, see what is actually logged. Open the command prompt and issue the following command:

logman.exe stop MyTrace -ets

This command simply stops the trace logging for the MyTrace log you started earlier. The MyTraceLog.etl file is a binary file and cannot be read directly. To extract information from MyTraceLog.etl file, you need to use the TraceRpt.exe (Trace Report) command line tool.

tracerpt MyTraceLog.etl

The above command creates two files, Summary.txt and Dumpfile.csv. The Summary.txt file contains information as shown below:

Files Processed:
MyTraceLog.etl
Total Buffers Processed 29
Total Events Processed 709
Total Events Lost 0
Start Time 4 Dec 2007 10:27:42.592
End Time 4 Dec 2007 10:31:52.231
Elapsed Time 249 sec
+------------------------------------------------------------+
|Event Count Event Name Event Type Guid |
+------------------------------------------------------------+
| 1 EventTrace Header {68fdd900-4a3e-11d1-84f4-0000f80464e3}|
| 6 AdoNetDiag TextW {7acdcac9-8947-f88a-e51a-24018f5129ef}|
| 702 System.Data TextW {914abde3-171e-c600-3348-c514171de148
| }|
+------------------------------------------------------------+

As you can see this file simply contains a summary of the trace log. The Dumpfile.txt file on the other hand contains detailed information about various events.

System.Data, TextW, 0x0EEC, 128412180408588592, 40, 100, 2,
"<sc.SqlCommand.set_Connection|API> 1# 1#", 0, 0
System.Data, TextW, 0x0EEC, 128412180408588592, 40, 100, 2,
   "<ds.DataSet.DataSet|API> 1#", 0, 0
System.Data, TextW, 0x0EEC, 128412180408588592, 40, 100, 2,
   "<ds.DataTableCollection.DataTableCollection|INFO>
   1# dataSet=1", 0, 0
System.Data, TextW, 0x0EEC, 128412180413195216, 60, 120, 2,
   "<sc.TdsParser.Connect|SEC> SSPI authentication", 0, 0
System.Data, TextW, 0x0EEC, 128412180454154112, 70, 170, 2,
   "<prov.DbConnectionFactory.CreatePooledConnection|RES|CPOOL>
   1# Pooled database connection created.", 0, 0
System.Data, TextW, 0x0EEC, 128412180454354400, 70, 170, 2,
   "<sc.SqlCommand.ExecuteReader|INFO> 1#
   Command executed as SQLBATCH.", 0, 0
System.Data, TextW, 0x0EEC, 128412180463467504, 70, 170, 2,
   "<ds.DataTable.DataTable|API> 1#", 0, 0
System.Data, TextW, 0x0EEC, 128412180463667792, 70, 170, 2,
   "<ds.DataColumn.DataColumn|API> 1# columnName='CustomerID'
   expr='(null)' type=1{ds.MappingType}", 0, 0
...

The Dumpfile.txt provides the following pieces of information:

  • EventName: Name of the event provider
  • EventType: Type of the event. For data providers, TextW indicates Unicode data and TextA indicates ASCII data.
  • TID: Thread identifier
  • Clock Time: A 64-bit integer that represents the timestamp at which the event took place
  • Kernel (ms): Processor time in milliseconds for which the event was in kernel mode
  • User (ms): Processor time in milliseconds for which the event was in user mode
  • User Data: Data about the event

If you observe the above trace carefully, you easily can identify various events happening in the system, such as theexecution of data reader, creation of DataTable, and so forth. Also, notice how the trace uses abbreviations of the namespace names. For example, comm refers to System.Data.Common namespace, ds refers to System.Data, screfers to System.Data.SqlClient, prov refers to System.Data.ProviderBase, and so on.

For better readability, you may open this file in MS Excel or the LogParser utility (from the IIS resource kit).

Summary

The ADO.NET trace logging feature allows you to trace information that can reveal important information about your data access code. The ADO.NET ETW providers are tuned for performance and can be turned on or off at runtime. This way, you can enable or disable tracing without affecting your application. The AdoNetDiag.dll plays a vital role in providing trace logging. The main command line tools used in ADO.NET trace logging are Mofcomp.exe, Logman.exe and TraceRpt.exe.

Download the Code

You can download the code that accompanies this article here.





Page 3 of 3



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel