// make sure we have an event log
if (!(EventLog.SourceExists("Application")))
{
EventLog.CreateEventSource("Application","Application");

} if (m_eventLog == null)
{
m_eventLog = new EventLog("Application");
m_eventLog.Source = "Application";
}

// log the message
m_eventLog.WriteEntry(message, System.Diagnostics.EventLogEntryType.Error);

解决方案 »

  1.   

    相应的目录,IIS设置为脚本和可执行权限
      

  2.   

    IIS执行权限都设置上了,但还是出错!
      

  3.   

    估计可能要把asp.net的用户加到adminstrator用户组里面
    其实可以把日志保存到一个数据表里面的
      

  4.   

    我的没有这个问题啊 ,不过我是用Administrator登录的! 帮你看看~
      

  5.   

    ASPNET has no rights to write to the event log. Try to set
    \\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Application\RestrictGuestAccess to 0 (reboot)ASPNET has also no rights to create event sources. Give ASPNET account
    read/write access to
    \\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog (and all
    sub keys)or set the userName in <processModel> in machine.config to "SYSTEM"
      

  6.   

    see an answer from Microsoft Developer Supporthttp://groups.google.com/groups?q=System.Security.SecurityException+eventlog+registry+support+microsoft&hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=m08t1iYrBHA.600%40cpmsftngxa09&rnum=3
      

  7.   

    创建新的事件源名称这句需要写入注册表的权限,简单的办法就是把ASPNET用户扔到备份组去
      

  8.   

    我 的机器上没有问题 ,放到别人的机器上 就会出现这个问题, 那边ASPNET用户还是Administrator的组呢,userName 是SYSTEM , 注册表的方法不敢试,怕老大砍。还有没有别的办法,
      

  9.   

    不好意思应该是改了用户的组 后重起IIS就可以了 。