logging file ด้วย Microsoft Enterprise Library

 

Microsoft Enterprise Library คือโปรแกรมที่ทาง Microsoft สร้างขึ้นมาเพื่ออำนวยความสะดวก สำหรับนักพัฒนาที่ใช้ภาษาตระกูล .NET ทั้งหลาย ที่สำคัญโปรแกรมนี้ไม่เสียค่าใช้จ่ายครับ สามารถดาวโหลดมาใช้กันได้อย่างฟรีๆ ความสามารถของโปรแกรมนี้มีมากมายเลย อาทิเช่น SqlConfiguration, PolicyInjection, Logging, Security และอื่นๆอีกเยอะแยะต้องลองเล่นดู แต่ที่ผมจะเขียนในบทความนี้ ผมจะแสดงวิธีสร้างและใช้งาน logging file ด้วย Microsoft Enterprise library การ logging file คือสร้าง logs file เอาไว้ตรวจสอบข้อมูลนั่นเองครับ

 

ก่อนอื่นต้อง Download program Microsoft enterprise library กันก่อน

 Download program ได้จากเว็บไซน์นี้ครับ http://msdn.microsoft.com/en-us/library/cc467894.aspx

 

การปรับแต่ง Microsoft enterprise library สำหรับไว้ใช้งาน

1. Download program Microsoft Enterprise Library from website และทำการ Install Program

 

2.หลังจาก Install program จนเสร็จเรียบร้อยแล้ว ให้เปิดโปรแกรมจากdirectory ที่ได้ทำการติดตั้งไว้

 

3. กดเม้าขวาเลือก New Application

 

4.กดเม้าขวาที่ Application ที่สร้างจากข้อ 3 แล้วเลือก Save Application

 

5.เลือก directory ที่ต้องการ save file ในกรณีที่ต้องการให้ทำการ logging เว็บไซค์ให้ brown ไปที่ directory ของเว็บไซค์ที่ต้องการ แล้วเลือก file *.config ของระบบที่ต้องการ แล้วกด save (ตัวโปรแกรมจะดึงค่าจาก config ของเว็บไซค์)

 

6.กดเม้าขวาที่ Application เลือก New->Logging Application Block

 

7.สำหรับ logging ให้ดูเฉพาะส่วน Logging Application Block ก็เพียงพอแล้ว

 

8.ในหัวข้อ Logging Application Block -> Formatters ตรงส่วนนี้จะเป็นตัวจัดการ รูปแบบการแสดงผลของ logs files ทางด้านขวามือให้เลือก <template> จะปรากฏหน้าต่างให้เราออกแบบรูปแบบข้อความ

enterprise-library-6

 

               8.1.ตัวอย่างรูปแบบใน config เมื่อเราทำงการกด save ระบบจะทำการ generate ข้อมูลใส่เพิ่มเข้าไปใน file config ของเราอัตโนมัต

 

1
2
3
4
5
6
7
<formatters>
      <add template="Timestamp: {timestamp}&#xD;&#xA;Message: {message}&#xD;&#xA;Category: {category}&#xD;&#xA;Priority: {priority}&#xD;&#xA;EventId: {eventid}&#xD;&#xA;Severity: {severity}&#xD;&#xA;Title:{title}&#xD;&#xA;Machine: {machine}&#xD;&#xA;Application Domain: {appDomain}&#xD;&#xA;Process Id: {processId}&#xD;&#xA;Process Name: {processName}&#xD;&#xA;Win32 Thread Id: {win32ThreadId}&#xD;&#xA;Thread Name: {threadName}&#xD;&#xA;Extended Properties: {dictionary({key} - {value}&#xD;&#xA;)}"
        type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="Error Text Formatter" />
      <add template="{title}	 {timestamp}	 {severity}	{message}" type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="Info Text Formatter" />
    </formatters>

 

ติดตามต่อใน Microsoft Enterprise Library ตอนที่ 2

 

 

 

Related Post
October 12th, 2008  |  by pat@codeburning.com  |  Published in .NET


ข้อมูลข่าวสาร

คำค้นยอดนิยม

Copyright Notice

  • สิทธิ์ในการเผยแพร่เป็นของท่าน
  • สิทธิ์ในทางพาณิชย์ไม่ได้เป็นของท่าน
  • สิทธิ์ในการเปลี่ยนแปลงไม่ได้เป็นของท่าน

Creative Commons License
Creative Commons Attribution 3.0