Enterprise Library 6.0 Semantic Logging application Block Configuration

Source: Internet
Author: User

Using the logging Application module of Enterprise Library 6.0, the configuration steps are as follows:

1.Nuget installation Enterprise Library logging module

Command line: Install-package enterpriselibrary.logging.

2. Configuration file:

The current basic is through Enterprise Library configuration, but unfortunately, I always install failure, so I Baidu A, and then configure, configured as follows:

<configsections>    < Sectionname= "Loggingconfiguration"type= "Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging "/>  </configsections>   <loggingconfigurationname=""tracingenabled= "true"defaultcategory= "General">        <Listeners>            <Addname= "Rolling Flat File Trace Listener"type= "Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging "Listenerdatatype= "Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging "Formatter= "Text Formatter"Rollinterval= "Day"rollsizekb= "1024x768"FileName= "App_data/trace.log"Maxarchivedfiles= "Ten" />        </Listeners>        <formatters>            <Addtype= "Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging "Template= "Timestamp: {timestamp}{newline}& #xA; title:{title}{newline}& #xA; severity:{severity}{newline}& #xA; Message: {message}{newline}& #xA; Extended Properties: {Dictionary ({key}-{value}{newline})} "name= "Text Formatter" />        </formatters>        <categorysources>            <AddSwitchvalue= "All"name= "General">                <Listeners>                    <Addname= "Rolling Flat File Trace Listener" />                </Listeners>            </Add>        </categorysources>        <specialsources>            <alleventsSwitchvalue= "All"name= "All Events" />            <notprocessedSwitchvalue= "All"name= "Unprocessed Category" />            <ErrorsSwitchvalue= "All"name= "Logging Errors &amp; Warnings ">                           </Errors>        </specialsources>    </loggingconfiguration>

3. Simple package logger, as follows:

  Public Sealed classLoghelper {Private StaticLoghelper instance =NULL; Static ReadOnly ObjectLockobj =New Object();  Public Staticloghelper Instance {Get            {                if(Instance = =NULL)                {                    Lock(lockobj) {if(instance==NULL) {instance=NewLoghelper (); }                    }                }                returninstance; }        }        PrivateLogWriter _logwriter =NULL; PrivateLoghelper () {Logwriterfactory factory=Newlogwriterfactory (); _logwriter=Factory.        Create (); }        Private voidLogcontent (System.Diagnostics.TraceEventType Tracetype,stringTitlestringmessage) {            if(_logwriter.isloggingenabled ()) {LogEntry entity=NewLogEntry (); Entity. Severity=Tracetype; Entity. TimeStamp=DateTime.Now; Entity. Message=message; Entity. Title=title;            _logwriter.write (entity); }        }                       /// <summary>        ///Log Exception infomation/// </summary>        /// <param name= "title" >Log title</param>        /// <param name= "ex" >Exception</param>         Public  voidlogexception (Exception ex) {logcontent (System.Diagnostics.TraceEventType.Error, ex. Message, ex.        ToString ()); }        

4. After testing, write the log.

Enterprise Library can refer to the Official document: Http://msdn.microsoft.com/zh-cn/library/dn169621.aspx

Enterprise Library 6.0 Semantic Logging application Block Configuration

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.