The SQL Anywhere .NET provider supports tracing using the .NET tracing feature. Note that tracing is not supported on Windows Mobile.
By default, tracing is disabled. To enable tracing, specify the trace source in your application's configuration file. Here's an example of the configuration file:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <system.diagnostics> <sources> <source name="iAnywhere.Data.SQLAnywhere" switchName="SASourceSwitch" switchType="System.Diagnostics.SourceSwitch"> <listeners> <add name="ConsoleListener" type="System.Diagnostics.ConsoleTraceListener"/> <add name="EventListener" type="System.Diagnostics.EventLogTraceListener" initializeData="MyEventLog"/> <add name="TraceLogListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="myTrace.log" traceOutputOptions="ProcessId, ThreadId, Timestamp"/> <remove name="Default"/> </listeners> </source> </sources> <switches> <add name="SASourceSwitch" value="All"/> <add name="SATraceAllSwitch" value="1" /> <add name="SATraceExceptionSwitch" value="1" /> <add name="SATraceFunctionSwitch" value="1" /> <add name="SATracePoolingSwitch" value="1" /> <add name="SATracePropertySwitch" value="1" /> </switches> </system.diagnostics> </configuration> |
The trace configuration information is placed in the application's bin\debug folder under the name app.exe.config.
The traceOutputOptions
that can be specified include the following:
Callstack Write the call stack, which is represented by the return value of the Environment.StackTrace property.
DateTime Write the date and time.
LogicalOperationStack Write the logical operation stack, which is represented by the return value of the CorrelationManager.LogicalOperationStack property.
None Do not write any elements.
ProcessId Write the process identity, which is represented by the return value of the Process.Id property.
ThreadId Write the thread identity, which is represented by the return value of the Thread.ManagedThreadId property for the current thread.
Timestamp Write the timestamp, which is represented by the return value of the System.Diagnostics.Stopwatch.GetTimeStamp method.
You can limit what is traced by setting specific trace options. By default the trace option settings are all 0. The trace options that can be set include the following:
SATraceAllSwitch The Trace All switch. When specified, all the trace options are enabled. You do not need to set any other options since they are all selected. You cannot disable individual options if you choose this option. For example, the following will not disable exception tracing.
<add name="SATraceAllSwitch" value="1" /> <add name="SATraceExceptionSwitch" value="0" /> |
SATraceExceptionSwitch All exceptions are logged. Trace messages have the following form.
<Type|ERR> message='message_text'[ nativeError=error_number] |
The nativeError=error_number text will only be displayed if there is an SAException object.
SATraceFunctionSwitch All function scope entry/exits are logged. Trace messages have any of the following forms.
enter_nnn <sa.class_name.method_name|API> [object_id#][parameter_names] leave_nnn |
The nnn is an integer representing the scope nesting level 1, 2, 3,... The optional parameter_names is a list of parameter names separated by spaces.
SATracePoolingSwitch All connection pooling is logged. Trace messages have any of the following forms.
<sa.ConnectionPool.AllocateConnection|CPOOL> connectionString='connection_text' <sa.ConnectionPool.RemoveConnection|CPOOL> connectionString='connection_text' <sa.ConnectionPool.ReturnConnection|CPOOL> connectionString='connection_text' <sa.ConnectionPool.ReuseConnection|CPOOL> connectionString='connection_text' |
SATracePropertySwitch All property setting and retrieval is logged. Trace messages have any of the following forms.
<sa.class_name.get_property_name|API> object_id# <sa.class_name.set_property_name|API> object_id# |
You can try application tracing using the TableViewer sample.
Start Visual Studio and open the TableViewer project file (TableViewer.sln) in samples-dir\SQLAnywhere\ADO.NET\TableViewer.
Place a copy of the configuration file shown above in the application's bin\debug folder under the name TableViewer.exe.config.
From the Debug menu, select Start Debugging.
When the application finishes execution, you will find a trace output file in samples-dir\SQLAnywhere\ADO.NET\TableViewer\bin\Debug\myTrace.log.
Tracing is not supported on Windows Mobile.
For more information, see "Tracing Data Access" at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadonet/html/tracingdataaccess.asp.
Discuss this page in DocCommentXchange.
|
Copyright © 2010, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.0 |