[5206][C#][SVN]如何擷取SVN Server的Windows事件
事件檢視器可指定事件類別為"VisualSVN Server 2.5",就可擷取SVN Server的Windows事件:
C#:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows.Forms;
namespace EventLogProject
{
static class Program
{
/// <summary>
/// 應用程式的主要進入點。
/// </summary>
[STAThread]
static void Main()
{
string logType = "";
// string logType = "Microsoft Office Sessions";
EventLog ev = new EventLog(logType, System.Environment.MachineName,"VisualSVN Server 2.5"); //可從篩選器過濾
//EventLog a = new EventLog(
int LastLogToShow = ev.Entries.Count;
if (LastLogToShow <= 0)
Console.WriteLine("No Event Logs in the Log :" + logType);
// Read the last 2 records in the specified log.
Int I;
for (I = ev.Entries.Count - 1; I >= LastLogToShow - 3; i--)
{
EventLogEntry CurrentEntry = ev.Entries[i];
//Console.WriteLine("Event ID : " + CurrentEntry.EventID);
//Console.WriteLine("Entry Type : " + CurrentEntry.EntryType.ToString());
//Console.WriteLine("Message : " + CurrentEntry.Message + "\n");
MessageBox.Show("Event ID:" + CurrentEntry.EventID);
MessageBox.Show("Entry Type : " + CurrentEntry.EntryType.ToString()); //Warning / Information / Error
MessageBox.Show("Message : " + CurrentEntry.Message + "\n");
MessageBox.Show("TimeG:" + CurrentEntry.TimeGenerated);
}
ev.Close();
}
}
}