本文整理汇总了C#中System.Diagnostics.EventLogEntry.Source属性的典型用法代码示例。如果您正苦于以下问题:C# EventLogEntry.Source属性的具体用法?C# EventLogEntry.Source怎么用?C# EventLogEntry.Source使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Diagnostics.EventLogEntry
的用法示例。
在下文中一共展示了EventLogEntry.Source属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
using System.Diagnostics;
class MyEventlogClass
{
public static void Main()
{
String myEventType=null;
// Associate the instance of 'EventLog' with local System Log.
EventLog myEventLog = new EventLog("System", ".");
Console.WriteLine("1:Error");
Console.WriteLine("2:Information");
Console.WriteLine("3:Warning");
Console.WriteLine("Select the Event Type");
int myOption=Convert.ToInt32(Console.ReadLine());
switch(myOption)
{
case 1: myEventType="Error";
break;
case 2: myEventType="Information";
break;
case 3: myEventType="Warning";
break;
default: break;
}
EventLogEntryCollection myLogEntryCollection=myEventLog.Entries;
int myCount =myLogEntryCollection.Count;
// Iterate through all 'EventLogEntry' instances in 'EventLog'.
for(int i=myCount-1;i>-1;i--)
{
EventLogEntry myLogEntry = myLogEntryCollection[i];
// Select the entry having desired EventType.
if(myLogEntry.EntryType.ToString().Equals(myEventType))
{
// Display Source of the event.
Console.WriteLine(myLogEntry.Source
+" was the source of last event of type "
+myLogEntry.EntryType);
return;
}
}
}
}