I am using log4net to log the errors in my application .Eveything works fine for the initial setup and logging. Now i want to set the Category and Event in the Eventlog.
I am using the below code to log the EventID ,but not sure about the category.
log4net.ThreadContext.Properties["EventID"] = 5;
Also how to differenciate the error levels [like i am getting the error message from Global.asax and logging the message to Eventlogs.But all the errors are going to log.error as below
}
else if (log.IsInfoEnabled)
{
log.Warn("Information" + sbErrorMessage.ToString());
}
else if (log.IsWarnEnabled)
{
log.Info("Warning" + sbErrorMessage.ToString());
}
I am not quite clear here..Like if i get an "InvalidOperationException" its an warning but the httpcode is 500 and it gets logged as "Error". I tried to get sbErrorMessage.innerExeception but its null.
Thanks in advance
I want all the errors,warning and information to be logged in one EventLog
Nilla2010
Member
48 Points
59 Posts
How to set the category and EventId in log4net
Oct 24, 2011 08:54 PM|LINK
I am using log4net to log the errors in my application .Eveything works fine for the initial setup and logging. Now i want to set the Category and Event in the Eventlog.
I am using the below code to log the EventID ,but not sure about the category.
log4net.ThreadContext.Properties["EventID"] = 5;
Also how to differenciate the error levels [like i am getting the error message from Global.asax and logging the message to Eventlogs.But all the errors are going to log.error as below
if ((log.IsErrorEnabled) && ((checkException.GetHttpCode() == 500) || (checkException.GetHttpCode() == 404)))
{
if(checkException.GetHttpCode() == 500)
log4net.ThreadContext.Properties["Category"] = "500";
else
log4net.ThreadContext.Properties["Category"] = "404";
log.Error("Error" + sbErrorMessage.ToString() );
}
else if (log.IsInfoEnabled)
{
log.Warn("Information" + sbErrorMessage.ToString());
}
else if (log.IsWarnEnabled)
{
log.Info("Warning" + sbErrorMessage.ToString());
}
I am not quite clear here..Like if i get an "InvalidOperationException" its an warning but the httpcode is 500 and it gets logged as "Error". I tried to get sbErrorMessage.innerExeception but its null.
Thanks in advance
I want all the errors,warning and information to be logged in one EventLog
log4net