After downloading the 1.2.11 version category is working fine
log4net.ThreadContext.Properties["Category"] = "404"; From: Venkatasamy, Vanitha [mailto:vanitha.venkatas...@xpandcorp.com] Sent: Tuesday, October 25, 2011 11:56 AM To: Log4NET User Cc: bode...@apache.org Subject: RE: How to set the category and EventId in EventLog log4net Stefan, Thank you for the reply . I corrected the mistake .I was trying out few things and forgot to switch it back. Yes you are right, it's not going to hit the last block. 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.IsWarnEnabled) { log.Warn("Warning" + sbErrorMessage.ToString()); } else if (log.IsInfoEnabled) { log.Info("Information" + sbErrorMessage.ToString()); } } 1.The version of log4net.dll I am using is 1.2.10 . 2.I tried setting the category as below, still its logs 'None' in the event Log.Is there any config changes I need to do? log4net.ThreadContext.Properties["Category"] = "500"; See the attachment 3.Yes you are correct ,I want to switch the level on the type of exception raised. The code is in Global.asax and I tried to get the innerExeception See the attachment Since the if (objErr.GetType() == typeof(HttpException)) { checkException = (HttpException)objErr; } checkException.GetHttpCode() =500 ,all the error are going into log.Error in my custom Event log. But if I check the system-application log,its logged as "Application" level. Thanks, Vanitha -----Original Message----- From: Stefan Bodewig [mailto:] Sent: Tuesday, October 25, 2011 10:52 AM To: Log4NET User Subject: Re: How to set the category and EventId in EventLog log4net On 2011-10-25, Venkatasamy, Vanitha wrote: > I am using log4net to log the errors in my application . Everything works > fine for the initial setup and logging. Now I want to set the Category and > Event in the Event log. > I am using the below code to log the EventID ,but not sure about the > category. > log4net.ThreadContext.Properties["EventID"] = 5; This should work using the Category property as you later show in your own post. This is a new feature of 1.2.11, though, the category is fixed in 1.2.10 and earlier. > log4net.ThreadContext.Properties["Category"] = "500"; should work as well as log4net.ThreadContext.Properties["Category"] = 500; > Also how to differentiate 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 Not sure I follow you here. > 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()); > } You have likely swapped IsInfoEnabled and IsWarnEnabled (as you use Warn if IsInfoEnabled and vice versa). Also note that IsWarnEnabled implies IsInfoEnabled so you never hit that last branch. > In addition ,I am not quite clear aout getting the Error,Warning and > Information separately ..Like if i get an "InvalidOperationException" > it's an warning but the httpcode is 500 and it gets logged as > "Error". I tried to get sbErrorMessage.innerExeception but its null. You mean you want to switch the level on the type of exception raised? Where is this code, inside Global.asax Application_Error method? Take a look at Server.GetLastError and maybe unwrap (i.e. look at the InnerException) if it is a HttpUnhandledException. Stefan ________________________________ This message contains Devin Group confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail in error and delete this e-mail from your system. E-mail transmissions cannot be guaranteed secure, error-free and information could be intercepted, corrupted, lost, destroyed, arrive late, incomplete, or contain viruses. The sender therefore does not accept liability for errors or omissions in the contents of this message which may arise as result of transmission. If verification is required please request hard-copy version. ________________________________ This message contains Devin Group confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail in error and delete this e-mail from your system. E-mail transmissions cannot be guaranteed secure, error-free and information could be intercepted, corrupted, lost, destroyed, arrive late, incomplete, or contain viruses. The sender therefore does not accept liability for errors or omissions in the contents of this message which may arise as result of transmission. If verification is required please request hard-copy version.