Filter content in ERRORLOG log file
過濾log檔案的內容
當你在Troubleshooting調查一個錯誤與問題時,如果ERRORLOG有大量不需要的紀錄,你可以使用以下方法來過濾。PS.當然如果你使用SSMS UI介面也是可以過濾,但用Command速度比較快一點。
1.Create a exclude text file(E:\Temp\Log\exclude.txt) with the contain below.
建立一個文字檔,填入要過濾的關鍵字,例如以下文字(每一行為一組關鍵字)
Error: 18456
Login failed for user
Login failed for user
2.Start a Command Prompt as an Administrator and run the command below.
執行以下命令產生過濾後的ERRORLOG檔
output exclude.txt以外的資料
type E:\Temp\Log\ERRORLOG | findstr /i /v /g:E:\Temp\Log\exclude.txt > E:\Temp\Log\ERRORLOG_Filtered.log
若只想output找到的那一行
type E:\Temp\Log\ERRORLOG | findstr /i /g:E:\Temp\Log\exclude.txt > E:\Temp\Log\ERRORLOG_Filtered.log
/i : Specifies that the search is not to be case-sensitive.
/v : Prints only lines that do not contain a match.
/g: file : Gets search strings from the specified file.
Reference:
https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-xp/bb490907(v=technet.10)?redirectedfrom=MSDN