上代码:if (System.Diagnostics.EventLog.SourceExists("DBAutoBackupService"))
            {
                System.Diagnostics.EventLog.DeleteEventSource("DBAutoBackupService");
            }
            EventLog.CreateEventSource("DBAutoBackupService", "DbABSLog");
            this.eventLog1.Source = "DBAutoBackupService";
            this.eventLog1.WriteEntry("日志测试");
            this.textBox1.Text = System.Diagnostics.EventLog.LogNameFromSourceName("DBAutoBackupService", 我的计算机名称);按MSDN所说,日志应该写入,但结果是日志依然写入Applictaion里,描述如下:
事件 ID ( 0 )的描述(在资源( DBAutoBackupService )中)无法找到。本地计算机可能没有必要的注册信息或消息 DLL 文件来从远端计算机显示消息。您可能可以使用 /AUXSOURCE= 标识来检索词描述;查看帮助和支持以了解详细信息。下列信息是事件的一部分: 日志测试.但textBox1的值取到的是DbABSLog也就是说,我将事件源注册到DbABSLog,系统也承认了,但写入日志的时候就是不往DbABSLog里写入,偏偏往Application日志里写,加上代码this.eventLog1.Log = "DbABSLog";结果也是一样的。

解决方案 »

  1.   

    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>0;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;
                   }
                }         }
       }EventLog