ASP.NET normally runs under ASPNET account which doesn't have permissions to create the event log entry, see
http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B329291
<%@ page language="c#"%>
<%@ Import Namespace="System.Diagnostics" %>
<% EventLog e1=new EventLog();
e1.Source="Test Source";
e1.Log="Test Log";
if(!EventLog.SourceExists(e1.Source))
{
EventLog.CreateEventSource(e1.Source,e1.Log);
}
e1.WriteEntry("Just look at me ",EventLogEntryType.Information,12);
e1.Close();
Response.Write("Done!");
}
http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B329291
<%@ page language="c#"%>
<%@ Import Namespace="System.Diagnostics" %>
<% EventLog e1=new EventLog();
e1.Source="Test Source";
e1.Log="Test Log";
if(!EventLog.SourceExists(e1.Source))
{
EventLog.CreateEventSource(e1.Source,e1.Log);
}
e1.WriteEntry("Just look at me ",EventLogEntryType.Information,12);
e1.Close();
Response.Write("Done!");
}
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(AreaImpl)); public AreaImpl()
{
} public void AddArea(Area area)
{
ISession s = HibernateUtil.OpenSession();
ITransaction t = s.BeginTransaction();
try
{
s.Save(area);
t.Commit();
log.Info("Save " + area.ToString() + " ...OK");
}
catch(Exception e)
{
t.Rollback();
log.Error("Save " + area.ToString() + " ...Failed!", e);
throw e;
}
finally
{
s.Close();
}
}
我需要一个工程文件,有的话发我一个学习的网页:http://www.ondotnet.com/pub/a/dotnet/2003/06/16/log4net.html?page=1
可我没学会!