解決方法一
提升ASPNET帳戶的許可權可以直接在Windows系統管理中給ASPNET帳戶添加對系統的讀寫權限,但是這樣做存在很嚴重的安全問題,asp.net進程有直接讀寫作業系統的許可權,將給系統帶來很大的安全隱患.
建議解決方法:
1>打開Regedit ,並找到下面的節點HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog
2>增加兩級項 比如:MyLog --WebLog
3>新寫一個安裝類
using System;
using System.Diagnostics;
using System.ComponentModel;
using System.Configuration.Install;
namespace EventLogSourceInstaller
{
[RunInstaller(true)]
public class MyEventLogInstaller: Installer
{
public EventLogInstaller myEventLogInstaller;
public MyEventLogInstaller()
{
//Create Instance of EventLogInstaller
myEventLogInstaller = new EventLogInstaller();
// Set the Source of Event Log, to be created.
myEventLogInstaller.Source = "WebLog";
// Set the Log that source is created in
myEventLogInstaller.Log = "TDDN";
Installers.Add(myEventLogInstaller);
}
}
}
將上面的編譯成dll,在.NET下的cmd注冊:InstallUtil EventLogSourceInstaller.dll
5>使用EventLog.WriteLogEventLog eventLog = null;
if (!(EventLog.SourceExists("WebLog"))){
EventLog.CreateEventSource("WebLog", "MyLog");
}
if (eventLog == null){
eventLog = new EventLog("MyLog");
eventLog.Source = "WebLog";
}
eventLog.WriteEntry("This is error!", EventLogEntryType.Error);