<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      Enterprise Library 2.0 Hands On Lab 翻譯(6):日志應(yīng)用程序塊(三)

      練習3:創(chuàng)建并使用自定義LogFormatter

      在本練習中將創(chuàng)建一個自定義的LogFormatter,并在應(yīng)用程序中使用它。

       

      第一步

      打開EnoughPI.sln項目,默認的安裝路徑應(yīng)該為C:\Program Files\Microsoft Enterprise Library January 2006\labs\cs\Logging\exercises\ex03\begin,并編譯。

       

      第二步 創(chuàng)建自定義LogFormatter

      1.在解決方案管理器中選擇Formatters\XmlFormatter.cs文件,選擇View | Code菜單命令,添加如下命名空間。

      using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;

      using Microsoft.Practices.EnterpriseLibrary.Logging;

      using Microsoft.Practices.EnterpriseLibrary.Logging.Configuration;

      using Microsoft.Practices.EnterpriseLibrary.Logging.Formatters;

      2.添加如下代碼到XmlFormatter類中。

      [ConfigurationElementType(typeof(CustomFormatterData))]

      public class XmlFormatter : LogFormatter

      {

          
      private NameValueCollection Attributes = null;

       

          
      public XmlFormatter(NameValueCollection attributes)

          
      {

              
      this.Attributes = attributes;

          }


       

          
      public override string Format(LogEntry log)

          
      {

              
      string prefix = this.Attributes["prefix"];

              
      string ns = this.Attributes["namespace"];

       

              
      using (StringWriter s = new StringWriter())

              
      {

                  XmlTextWriter w 
      = new XmlTextWriter(s);

                  w.Formatting 
      = Formatting.Indented;

                  w.Indentation 
      = 2;

       

                  w.WriteStartDocument(
      true);

                  w.WriteStartElement(prefix, 
      "logEntry", ns);

                  w.WriteAttributeString(
      "Priority", ns,

                      log.Priority.ToString(CultureInfo.InvariantCulture));

                  w.WriteElementString(
      "Timestamp", ns, log.TimeStampString);

                  w.WriteElementString(
      "Message", ns, log.Message);

                  w.WriteElementString(
      "EventId", ns,

                      log.EventId.ToString(CultureInfo.InvariantCulture));

                  w.WriteElementString(
      "Severity", ns, log.Severity.ToString());

                  w.WriteElementString(
      "Title", ns, log.Title);

                  w.WriteElementString(
      "Machine", ns, log.MachineName);

                  w.WriteElementString(
      "AppDomain", ns, log.AppDomainName);

                  w.WriteElementString(
      "ProcessId", ns, log.ProcessId);

                  w.WriteElementString(
      "ProcessName", ns, log.ProcessName);

                  w.WriteElementString(
      "Win32ThreadId", ns, log.Win32ThreadId);

                  w.WriteElementString(
      "ThreadName", ns, log.ManagedThreadName);

                  w.WriteEndElement();

                  w.WriteEndDocument();

       

                  
      return s.ToString();

              }


          }


      }

      日志項將被格式化為XML格式,并且它期望接收兩個參數(shù)prefixnamespace

      3.選擇Build | Build Solution編譯整個解決方案。

       

      第三步 使用自定義LogFormatter

      1.在解決方案管理器中選擇項目EnoughPI的配置文件App.config文件,選擇View | Open With…菜單命令,選擇Enterprise Library Configuration并單擊OK按鈕。

      2.選中Logging Application Block | Formatters節(jié)點,選擇Action | New | Custom Formatter菜單命令,并設(shè)置屬性Name的為Xml Formatter

      3.選擇Type屬性,單擊ellipses顯示Type Selector對話框。

      4.從程序集EnoughPI.Logging中選擇XmlFormatter類并單擊OK按鈕。

      Type Selector列表中的類,來自于與Enterprise Library Configuration配置工具在同一目錄下的程序集,它們繼承于基類LogFormatter,并且有一個值為CustomTraceListenerData的特性ConfigurationElementType。

      5.選擇Attributes屬性并單擊ellipses顯示EditableKeyValue Collection Editor。

      6.添加如下鍵值對

      Key = prefix, Value = x

      Key = namespace, Value = EnoughPI/2.0

      并單擊OK按鈕。

      還記得在類XmlFormatter中期望接受的兩個參數(shù)prefixnamespace。

      7.選擇Logging Application Block | Trace Listeners | Custom TraceListener節(jié)點,并設(shè)置屬性FormatterXml Formatter。

      8.選擇File | Save All保存配置,并關(guān)閉Enterprise Library Configuration工具。

      9.選擇Debug | Start Without Debugging菜單命令并運行應(yīng)用程序,EnoughPI程序用來計算∏的精度。在NumericUpDown控件中輸入你希望的精度并點擊Calculate按鈕。可以看到日志項顯示在一個控制臺窗口中。

      完成后的解決方案代碼如C:\Program Files\Microsoft Enterprise Library January 2006\labs\cs\Logging\exercises\ex03\end所示。

       

      注意根據(jù)Hands On Lab給出的時間建議,做完以上三個練習的時間應(yīng)該為30分鐘。

       

      更多Enterprise Library的文章請參考《Enterprise Library系列文章
      posted @ 2006-10-06 17:13  TerryLee  閱讀(6939)  評論(3)    收藏  舉報
      主站蜘蛛池模板: 中文熟妇人妻av在线| 黑人玩弄人妻中文在线| 欧洲亚洲色一区二区色99| 欧美大屁股喷潮水xxxx| 欧美国产亚洲日韩在线二区| 国产AV无码专区亚洲AWWW| 成人午夜在线观看日韩| 亚洲精品不卡av在线播放| 东京热高清无码精品| 国产乱妇无码大片在线观看| 国产精品一区二区国产馆| 黑森林福利视频导航| 亚洲色一色噜一噜噜噜| 国产av仑乱内谢| 日韩亚洲欧美中文高清| 精品偷拍被偷拍在线观看| 欧美性白人极品hd| 国产国产久热这里只有精品| 国产中文字幕在线精品| 99久久久国产精品免费无卡顿| 婷婷综合亚洲| 国产在线视频精品视频| 国产精品毛片av999999| 日本大片在线看黄a∨免费| 日韩精品亚洲专区在线观看| 久久精品国产亚洲av麻豆不卡| 老司机午夜精品视频资源| 亚洲人成电影在线天堂色| 国产精品亚洲二区在线播放| 国偷自产一区二区三区在线视频| 国产午夜福利免费入口| 宣武区| 亚洲欧美日韩在线码| 成人精品天堂一区二区三区| 国产亚洲国产精品二区| 国产精品亚洲片夜色在线| 精品无码三级在线观看视频| 日韩中文字幕av有码| 国产区精品福利在线熟女| 国产精品一二三中文字幕| 久久一亚色院精品全部免费|