[Log application block] Experiment 2: creating and using asynchronous Trace Listener

Source: Internet
Author: User

To monitor how long the log entries takeLength of monitoring log entries

    Event Log Trace ListenerFrom BuildProgrammaticConfigMethod in EntryPoint. csSo you are only keeping track of the time it takes to log using your Flat File Trace Listener.Set EntryPoint. csFile BuildProgrammaticConfigThe Event Log Trace in the method is commented out or deleted, so that you only record Flat File Trace ListenerThe time of the record.

     

                 TextFormatter formatter =  TextFormatter(          xmlFormatterAttributes =      xmlFormatterAttributes[] =      xmlFormatterAttributes[] =      EnoughPI.Logging.Formatters.XmlFormatter xmlFormatter =                      eventLog =  EventLog(, ,        eventLogTraceListener =          flatFileTraceListener =                                                 config =                         }

     

  1. Debug | Start Without DebuggingMenu command to run the application. Enter a precision of at least 300 (this will make the time improvements more apparent) and clickCalculateButton. The end of the Tracing logs inC: \ Temp \ trace. logWill tell how long it took to calculate pi. Select debug | start to execute (not Debug) the menu command to run the program. Enter at least 300 (more) and click the Calculate button. In the fileC: \ Temp \ trace. logWill tell you how long it takes to calculate the PI value.

     

     

     

To use a trace listener asynchronouslyUse asynchronous Trace Listener

    AddAsynchronousTraceListenerMethod in BuildProgrammaticConfigMethod in EntryPoint. csTo add the flatFileTraceListener to your configuration. EntryPoint. csFile BuildProgrammaticConfigMethod call AddAsynchronousTraceListenerMethod to add it to your configuration information.
                 TextFormatter formatter =  TextFormatter(             {severity}{newline}Title:{title}{newline}             flatFileTraceListener =           FlatFileTraceListener(                                config =           (flatFileTraceListener);      config.IsTracingEnabled =       }

    FlatFileTraceListenerAllows you to use thatTrace ListenerTo log messages asynchronously. This will be most useful when writing large volumes of messages to a flat file or database. Wrap existing FlatFileTraceListener so that you can use TraceListener to asynchronously record messages. This is useful when recording a large number of log messages to files or databases.

  1.  

     

Logging messages asynchronously can lead to messages being lost if the application terminates before the buffer is drained. Disposing the LogWriter when shutting down the application attempts to flush all asynchronous buffers.

If the program is terminated before the buffer is emptied, asynchronous message recording may cause message loss. When the program is closed, LogWriter processes all asynchronous buffers.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.