Enterprise Library Logging 快速上手
这篇文章将演示花费最小的代价使用Microsoft’s Enterprise Library 4.1在你的应用程序中记录日志。下面是一些细节,第一次如何在代码logging Message:
下载安装Enterprise Library 4.1
让我们开始,创一个VS控制台程序名叫HelloWorldEntLibLogging,在项目中引用Ent. Lib. logging assembly,如图:
为应用程序配制Logging,增加一个App.config
在App.config文件上单击右键:
在弹出的菜单编辑器选择New | Logging Application Block
这时一个新的Logging Application Block 配制节点是这样的:
接着,打开App.config的XML内容是:
1: <?xml version="1.0" encoding="utf-8"?>
2: <configuration>
3: <configSections>
4: <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
5: <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
6: </configSections>
7: <loggingConfiguration name="Logging Application Block" tracingEnabled="true"
8: defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
9: <listeners>
10: <add source="Enterprise Library Logging" formatter="Text Formatter"
11: log="Application" machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
12: traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
13: name="Formatted EventLog TraceListener" />
14: </listeners>
15: <formatters>
16: <add template="Timestamp: {timestamp} Message: {message} Category: {category} Priority: {priority} EventId: {eventid} Severity: {severity} Title:{title} Machine: {machine} Application Domain: {appDomain} Process Id: {processId} Process Name: {processName} Win32 Thread Id: {win32ThreadId} Thread Name: {threadName} Extended Properties: {dictionary({key} - {value} )}"
17: type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0,
补充:软件开发 , C# ,