Use tracing to generate log (data synchronization log) [desktop]
The sync Service for Ado.net is an important part of Microsoft's MSF (Microsoft Sync Framework), which provides a complete development framework for synchronizing offline data with various scenarios. We can use it to develop some complex scenarios to adapt to complex enterprise logic. For example, in a distributed scenario: we create a server and then use the Sync Service for ado.net to synchronize data using dozens of or thousands of PCs, notebook, and WM Device (mobile PDA mobile devices) as client segments.
For this complex distributed synchronization scenario, how to debug and correct it? Tracing in Sync Services is required at this time.
What is tracing in Sync Services?
Tracing records the various operations of the program, including synchronizing data and metadata, and then gives the information to Listener. As a Listener, this information can be recorded in a file as log logs, or other places that are transmitted according to your request. In a distributed program, tracing is very important because you need to use it to debug bugs in the program to find the root cause of the problem. Otherwise, it is very difficult to find the root cause of the problem.
How to start opening tracing in Sync Services
By default, tracing is turned off. We can turn on tracing by configuring Trace Listener.
We can edit the app.config to open the tracing, please add the following code:
<configuration>
<system.diagnostics>
<switches>
<!-- 0-off, 1-error, 2-warn, 3-info, 4-verbose. -->
<add name="SyncTracer" value="3" />
</switches>
<trace autoflush="true">
<listeners>
<add name="TestListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="c:\TraceSample.txt"/>
</listeners>
</trace>
</system.diagnostics>
</configuration>
How to select the appropriate trace level
Trace records have some performance implications, and you need to seriously consider how to set up TraceLevel to balance trace records against product performance.
Typically, if you just want to monitor the error message, choose Tracelevel=1 or 2. When you need more log information to facilitate debugging observation, you can tracelevel=3 or 4, remember that this time the log generated is very detailed, and its corresponding log file will be very large-this will give the performance of the program has no small impact. In general, we will only use this tracelevel in debugging errors and in the development process.
For more information, see the following table:
switch value |
tr Acing level |
output |
0 |
off |
no messages to trace listener S. |
error |
only error messages to trace listeners. |
warning |
error and warning messages to trace listeners. |
info |
informational, warning, and error messages to trace listeners. |
4 |
verbose |
all messages to trace listeners. |