Tarun
Tarun

Reputation: 393

c# tracing system.diagnostics

I am using a sync service to sync between compact database and server. In web.config, i am diagnosing the sync and logging in the file like this:

<system.diagnostics>
   <sources>
      <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
         <listeners>
            <add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="C:\MISTYLogs\SYNCService\syncTraces.svclog"></add>
         </listeners>
      </source>
   </sources>
   <switches>
      <add name="SyncTracer" value="3"/>
   </switches>
   <trace autoflush="true">
      <listeners>
         <add name="SyncListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="C:\MISTYLogs\SYNCService\syncinf.txt"/>
      </listeners>
   </trace>
</system.diagnostics>

During sync process, the file size becomes more than one gb. I want to restrict the log file size to some limit and after crossing that limit, it should create another log file and so on. How to achieve this using configuration settings??

Kindly suggest?

Upvotes: 2

Views: 9339

Answers (1)

Mikael Svenson
Mikael Svenson

Reputation: 39697

Look into using the FileLogTraceListener.

The FileLogTraceListener class provides automated maintenance capabilities to archive log files as needed, on a daily or per-application basis. This automatic archival functionality helps reduce the maintenance responsibilities of developers and administrators.

Upvotes: 1

Related Questions