读windows日志

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

using System.Diagnostics;

public partial class Default3 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
     {
        //Windows日志有:"Application"应用程序, "Security"安全, "System"系统
        string[] logs = new string[] { "Application", "System" };

         StringBuilder result = new StringBuilder();

        foreach (string log in logs)
         {
             EventLog myLog = new EventLog();
             myLog.Log = log;
            //myLog.MachineName = "rondi-agt0qf9op";
            foreach (EventLogEntry entry in myLog.Entries)
             {
                //EventLogEntryType枚举包括:
                //Error 错误事件。
                //FailureAudit 失败审核事件。
                //Information 信息事件。
                //SuccessAudit 成功审核事件。
                //Warning 警告事件。
                if (entry.EntryType == EventLogEntryType.Error || entry.EntryType == EventLogEntryType.Warning)
                 {
                     result.Append("<font color='red'>" + log);
                     result.Append(entry.EntryType.ToString() + "</font>");
                     result.Append("<font color='blue'>(" + entry.TimeWritten.ToString() + ")</font>:");
                     result.Append(entry.Message + "<br /><br />");
                 }
             }
         }
         Response.Write(result.ToString());
     }
} 


你可能感兴趣的:(读windows日志)