如何讓 IIS7 的存取記錄(Logs)從緩衝區強制寫入到磁碟 (zh-TW)

如何讓 IIS7 的存取記錄(Logs)從緩衝區強制寫入到磁碟 (zh-TW)

前幾天我們公司的一個網站專案上線,由於是第一天上線且經常使用的網站使用者又多達數萬人,也因此第一天上線時狀況頗多,所以需要收集各式紀錄,包括 EventLog, IIS Logs, URLScan Logs, … 等,但唯讀 IIS7 的 Logs 常常抓不到最新的資料,那是因為 IIS 的 Logs 預設都有緩衝(Buffer)機制,因此 IIS 的存取紀錄都會延遲寫入磁碟,所以若直接複製 Logs 檔案將不會是最新資料,大部分人都會利用 IISRESET 重新啟動 IIS 來取得最新的 Logs,但這並非正規的作法,今天我分享另一個技巧。

IIS7 在 Network Shell (Netsh) 指令列工具新增了對 HTTP service 的支援,現有支援的指令可以到 Netsh Commands for Hypertext Transfer Protocol (HTTP) 查詢到。

這其中就有一個 flush logbuffer 指令可以刷新(Flush)在緩衝區(Buffer)尚未寫入磁碟的 Logs 資料:

netsh http flush logbuffer

netsh http flush logbuffer

所以當你在要取得目前最新的 IIS Logs 之前只要執行這行指令就可以拿到到目前為止最新的 Logs 紀錄。

相關連結

Leave a Comment
  • Please add 6 and 1 and type the answer here:
  • Post
Wiki - Revision Comment List(Revision Comment)
Sort by: Published Date | Most Recent | Most Useful
Comments
  • Ed Price MSFT edited Original. Comment: Updated title with Traditional Chinese guidelines. Please change as appropriate.

Page 1 of 1 (1 items)
Wikis - Comment List
Sort by: Published Date | Most Recent | Most Useful
Posting comments is temporarily disabled until 10:00am PST on Saturday, December 14th. Thank you for your patience.
Comments
  • Ed Price MSFT edited Original. Comment: Updated title with Traditional Chinese guidelines. Please change as appropriate.

Page 1 of 1 (1 items)