You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by Dave Weaver <da...@loggr.net> on 2011/08/17 15:58:58 UTC
Looking for users to try out new Log4Net appender service
If your interested in trying out Loggr.net as a hosted backend service for
Log4Net, please reply to this email.
Thanks
--
*Dave Weaver*
Loggr
Email: dave@loggr.net
Mobile: (717) 201-2010
How to use log4net in dll
Posted by "Venkatasamy, Vanitha" <Va...@xpandcorp.com>.
Hi,
After spending a week for the log4net implementation which has to log errors from both aspx and asp files , i am still out with no luck. This is my scenario, my project contains both asp and aspx pages. The aspx page errors are captured in Globals.asax and send to Errorlogging.dll ,where i have log4net implemention to log the errors to EventViewer and its works just fine.
Other part is for ASP pages ,i am accesing the same Errorlogging.dll ,but different method to log the error. Here isDebugenabled is true,but the errors are not logged into the EventViewer.
1.I am using the same Eventviewer log file for both methods
2.The method which logs aspx errors ,take the configurations from web.config
3.But for the method which logs asp errors,i am using seperate log4net.config file.
Questions
Do i need to maintain two diffferent config's for each methods?
I dont think its permission issue, bse the other method works just fine.
Only thing is the config section .
Is there any locking issue here
Thanks,
CODE
public static readonly ILog log = LogManager.GetLogger(typeof(ErrorLogging).Name);
public ErrorLogging()
{
}
//ASP
public String logEventErrorASP(String sourceName, String logName, String objErr, String strBotListPath)
{
// log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo(AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "log4net.config"));
log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo(Path.GetDirectoryName(Assembly.GetAssembly(GetType()).Location) + @"\" + "log4net.config"));
String tempVar=Path.GetDirectoryName(Assembly.GetAssembly(GetType()).Location) + @"\" + "log4net.config";
//log4net.Config.XmlConfigurator.Configure();
//log4net.ThreadContext.Properties["EventID"] = 5;
String tempdata = string.Empty;
if (!System.Diagnostics.EventLog.SourceExists(sourceName))
{
tempdata = sourceName + logName + objErr + strBotListPath;
System.Diagnostics.EventLog.CreateEventSource(sourceName, logName);
}
else
{
// Exception ex = (Exception)objErr;
if (log.IsErrorEnabled)
{
log.Error("There is an error " + objErr);
tempdata = "Warning ";
}
if (log.IsWarnEnabled)
{
tempdata = tempdata + "Fatal";
try
{
log.Warn(" Unhandled error!" + objErr);
}
catch (Exception ex)
{
tempdata = tempdata + ex.ToString();
}
}
}
return tempdata + " "+ tempVar;
//return ConfigurationSettings.AppSettings["log4net.config"].ToString();
}
//ASP.NET
public String logEventError(String sourceName, String logName, HttpContext errContext, HttpRequest errRequest, Exception objErr, string strBotListPath)
{
log4net.Config.XmlConfigurator.Configure();
log4net.ThreadContext.Properties["EventID"] = 5;
if (!System.Diagnostics.EventLog.SourceExists(sourceName))
{
System.Diagnostics.EventLog.CreateEventSource(sourceName, logName);
}
if (log.IsErrorEnabled)
{
log.Error("Page Load failed : " + objErr);
}
//Custom Error Page
string strErrorPage;
HttpException checkException = new HttpException();
if (objErr.GetType() == typeof(HttpException))
{
checkException = (HttpException)objErr;
}
if (checkException.GetHttpCode() == 404)
{
strErrorPage = "~/404.aspx";
}
else
{
strErrorPage = "~/500.aspx";
}
//if (blnLog404 || checkException.GetHttpCode() != 404)
//{
if (File.Exists(strBotListPath))
{
XmlDocument document = new XmlDocument();
document.Load(strBotListPath);
XmlNodeList xmlUserAgentList = document.SelectNodes("//UserAgent");
foreach (XmlNode node in xmlUserAgentList)
{
string botName = node.InnerText.ToString();
//string botName = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
bool isBot = errRequest.ServerVariables["ALL_RAW"].ToUpper().Contains(botName.ToUpper());
if (isBot)
{
return strErrorPage;
}
}
}
return strErrorPage;
}
________________________________
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.
RE: How to do configuration in assembly.cs file for log4net
implementation?
Posted by "Venkatasamy, Vanitha" <Va...@xpandcorp.com>.
Thank you for the suggestions .
I tried by setting the priority level to ALL and changing the loop statements. But still , I have no clue where those error messages are getting logged. More info on the background is,
1.I am calling a .Net dll project from a ASP page ,the parameter includes the error string.
2.In my dll project ,I have the log4net implementation .
Code
public static readonly ILog log = LogManager.GetLogger(typeof(ErrorLogging).Name);
public String logEventErrorASP(String sourceName, String logName, String objErr, String strBotListPath)
{
log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo(AppDomain.CurrentDomain.SetupInformation.ApplicationBase+"log4net.config"));
//log4net.Config.XmlConfigurator.Configure();
log4net.ThreadContext.Properties["EventID"] = 6;
String tempdata = string.Empty;
if (!System.Diagnostics.EventLog.SourceExists(sourceName))
{
tempdata = sourceName + logName + objErr + strBotListPath;
System.Diagnostics.EventLog.CreateEventSource(sourceName, logName);
}
else
{
// Exception ex = (Exception)objErr;
if (log.IsFatalEnabled)
{
log.Fatal("There is an error " + objErr);
tempdata = "Warning ";
}
if (log.IsWarnEnabled)
{
tempdata = tempdata + "Fatal";
try
{
log.Warn(" Unhandled error!" + objErr);
}
catch (Exception ex)
{
tempdata = tempdata + ex.ToString();
}
}
}
return tempdata+AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "log4net.config";
}
3.I placed the config file in C:\windows\system32\inetsrv\ log4net.config
4. The output in my asp page is Warning Fatal c:\windows\system32\inetsrv\log4net.config.which means fatal and warning are all returning true.
5.I checked the eventviewer is created but no errors.
5.The event viewer is working fine for aspx pages which is using the method in the same dll .The log4net implementation is in Global.asax for the aspx errors and for my asp pages I am passing the error to dll,which has the log4net implementation separately for the logging the error [ Anything wrong]
Thanks
Vanitha
From: Roy Chastain [mailto:]
Sent: Wednesday, August 17, 2011 10:24 AM
To: Log4NET User
Subject: RE: How to do configuration in assembly.cs file for log4net implementation?
One note for future reference
if (log.IsDebugEnabled)
{
log.Debug("This is a DEBUG level message. The most VERBOSE level.");
log.Info("Extended information, with higher importance than the Debug call");
log.Warn("An unexpected but recoverable situation occurred");
tempdata = "Source already exits";
Probably does not do what you want. Either or both Info and Warn could be enabled without Debug being enabled.
Try changing Priority to Level in the <root>
If you still do not get log entries, try a more simple appender such as a RollingLogFile etc. The EventLog appender has proven difficult for many people and it gets worse under Vista/2008 and above.
----------------------------------------------------------------------
Roy Chastain
From: Venkatasamy, Vanitha [mailto:Vanitha.Venkatasamy@xpandcorp.com]
Sent: Wednesday, August 17, 2011 10:04
To: Log4NET User
Subject: How to do configuration in assembly.cs file for log4net implementation?
HI,
I am trying to implement the log4net. In my project ,i am referring a dll project,which has the log4net implementation and i am calling the dll from from my asp number.
The call is successful from asp to dll method and the logger is created just fine.
private static readonly ILog log = LogManager.GetLogger(typeof(ErrorLogging).Name);
But the problem is the logger is not enabled. I mean IsErrorEnabled/IsDebugEnabled are false.
The confusing part to me is assembly.cs,in which the place where we mention the
[assembly: log4net.Config.XmlConfigurator(ConfigFileExtension = "log4net", Watch = true)]
// This will cause log4net to look for a configuration file
// called TestApp.exe.log4net in the application base
// directory (i.e. the directory containing TestApp.exe)
// The config file will be watched for changes.
So ,do i need to create a file with .log4net extension ,if so i tried and its not working.
And not working from my web.config also.
Please see my web.config code
<log4net debug="true">
<appender name="EventLogAppender" type="log4net.Appender.EventLogAppender">
<param name="LogName" value="PortalWebLog" />
<param name="ApplicationName" value="Portal" />
<eventId value="6" />
<eventCategory value="10" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
<root>
<priority value="DEBUG" />
<appender-ref ref="EventLogAppender" />
</root>
</log4net>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
And the dll method ,where i am accesing the log
log4net.Config.XmlConfigurator.Configure();
log4net.ThreadContext.Properties["EventID"] = 6;
String tempdata=string.Empty;
if (!System.Diagnostics.EventLog.SourceExists(sourceName))
{
tempdata = sourceName + logName + objErr + strBotListPath;
System.Diagnostics.EventLog.CreateEventSource(sourceName, logName);
}
else
{
if (log.IsDebugEnabled)
{
log.Debug("This is a DEBUG level message. The most VERBOSE level.");
log.Info("Extended information, with higher importance than the Debug call");
log.Warn("An unexpected but recoverable situation occurred");
tempdata = "Source already exits";
}
else
{
tempdata = "Source already exits,but debug not enabled";
}
}
After removing the below line
[assembly: log4net.Config.XmlConfigurator(ConfigFileExtension = "log4net", Watch = true)],
and by placing the log4net.config in C:\windows\system32\inetsrv,the error log is enabled and changing the line,
log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo(AppDomain.CurrentDomain.SetupInformation.ApplicationBase+"log4net.config"));
The IsDebugEnabled is true but i am not seeing any errors in the eventLog and its empty
DEV Environment :Windows 2003 ,log4net for .Net framework2.0 [1.2.10.0]
Thanks,
Vanitha Venkatasamy
XPAND Corporation.
[cid:image001.jpg@01CC5CCE.B5285740]
________________________________
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.
RE: How to do configuration in assembly.cs file for log4net implementation?
Posted by Roy Chastain <Ro...@roychastain.org>.
One note for future reference
if (log.IsDebugEnabled)
{
log.Debug("This is a DEBUG level message. The most
VERBOSE level.");
log.Info("Extended information, with higher
importance than the Debug call");
log.Warn("An unexpected but recoverable situation
occurred");
tempdata = "Source already exits";
Probably does not do what you want. Either or both Info and Warn could
be enabled without Debug being enabled.
Try changing Priority to Level in the <root>
If you still do not get log entries, try a more simple appender such as
a RollingLogFile etc. The EventLog appender has proven difficult for
many people and it gets worse under Vista/2008 and above.
----------------------------------------------------------------------
Roy Chastain
From: Venkatasamy, Vanitha [mailto:Vanitha.Venkatasamy@xpandcorp.com]
Sent: Wednesday, August 17, 2011 10:04
To: Log4NET User
Subject: How to do configuration in assembly.cs file for log4net
implementation?
HI,
I am trying to implement the log4net. In my project ,i am referring a
dll project,which has the log4net implementation and i am calling the
dll from from my asp number.
The call is successful from asp to dll method and the logger is
created just fine.
private static readonly ILog log =
LogManager.GetLogger(typeof(ErrorLogging).Name);
But the problem is the logger is not enabled. I mean
IsErrorEnabled/IsDebugEnabled are false.
The confusing part to me is assembly.cs,in which the place where we
mention the
[assembly: log4net.Config.XmlConfigurator(ConfigFileExtension =
"log4net", Watch = true)]
// This will cause log4net to look for a configuration file
// called TestApp.exe.log4net in the application base
// directory (i.e. the directory containing TestApp.exe)
// The config file will be watched for changes.
So ,do i need to create a file with .log4net extension ,if so i tried
and its not working.
And not working from my web.config also.
Please see my web.config code
<log4net debug="true">
<appender name="EventLogAppender"
type="log4net.Appender.EventLogAppender">
<param name="LogName" value="PortalWebLog" />
<param name="ApplicationName" value="Portal" />
<eventId value="6" />
<eventCategory value="10" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger
[%property{NDC}] - %message%newline" />
</layout>
</appender>
<root>
<priority value="DEBUG" />
<appender-ref ref="EventLogAppender" />
</root>
</log4net>
<configSections>
<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
And the dll method ,where i am accesing the log
log4net.Config.XmlConfigurator.Configure();
log4net.ThreadContext.Properties["EventID"] = 6;
String tempdata=string.Empty;
if (!System.Diagnostics.EventLog.SourceExists(sourceName))
{
tempdata = sourceName + logName + objErr +
strBotListPath;
System.Diagnostics.EventLog.CreateEventSource(sourceName, logName);
}
else
{
if (log.IsDebugEnabled)
{
log.Debug("This is a DEBUG level message. The most
VERBOSE level.");
log.Info("Extended information, with higher
importance than the Debug call");
log.Warn("An unexpected but recoverable situation
occurred");
tempdata = "Source already exits";
}
else
{
tempdata = "Source already exits,but debug not
enabled";
}
}
After removing the below line
[assembly: log4net.Config.XmlConfigurator(ConfigFileExtension =
"log4net", Watch = true)],
and by placing the log4net.config in C:\windows\system32\inetsrv,the
error log is enabled and changing the line,
log4net.Config.XmlConfigurator.ConfigureAndWatch(new
FileInfo(AppDomain.CurrentDomain.SetupInformation.ApplicationBase+"log4n
et.config"));
The IsDebugEnabled is true but i am not seeing any errors in the
eventLog and its empty
DEV Environment :Windows 2003 ,log4net for .Net framework2.0 [1.2.10.0]
Thanks,
Vanitha Venkatasamy
XPAND Corporation.
________________________________
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.
How to do configuration in assembly.cs file for log4net
implementation?
Posted by "Venkatasamy, Vanitha" <Va...@xpandcorp.com>.
HI,
I am trying to implement the log4net. In my project ,i am referring a dll project,which has the log4net implementation and i am calling the dll from from my asp number.
The call is successful from asp to dll method and the logger is created just fine.
private static readonly ILog log = LogManager.GetLogger(typeof(ErrorLogging).Name);
But the problem is the logger is not enabled. I mean IsErrorEnabled/IsDebugEnabled are false.
The confusing part to me is assembly.cs,in which the place where we mention the
[assembly: log4net.Config.XmlConfigurator(ConfigFileExtension = "log4net", Watch = true)]
// This will cause log4net to look for a configuration file
// called TestApp.exe.log4net in the application base
// directory (i.e. the directory containing TestApp.exe)
// The config file will be watched for changes.
So ,do i need to create a file with .log4net extension ,if so i tried and its not working.
And not working from my web.config also.
Please see my web.config code
<log4net debug="true">
<appender name="EventLogAppender" type="log4net.Appender.EventLogAppender">
<param name="LogName" value="PortalWebLog" />
<param name="ApplicationName" value="Portal" />
<eventId value="6" />
<eventCategory value="10" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
<root>
<priority value="DEBUG" />
<appender-ref ref="EventLogAppender" />
</root>
</log4net>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
And the dll method ,where i am accesing the log
log4net.Config.XmlConfigurator.Configure();
log4net.ThreadContext.Properties["EventID"] = 6;
String tempdata=string.Empty;
if (!System.Diagnostics.EventLog.SourceExists(sourceName))
{
tempdata = sourceName + logName + objErr + strBotListPath;
System.Diagnostics.EventLog.CreateEventSource(sourceName, logName);
}
else
{
if (log.IsDebugEnabled)
{
log.Debug("This is a DEBUG level message. The most VERBOSE level.");
log.Info("Extended information, with higher importance than the Debug call");
log.Warn("An unexpected but recoverable situation occurred");
tempdata = "Source already exits";
}
else
{
tempdata = "Source already exits,but debug not enabled";
}
}
After removing the below line
[assembly: log4net.Config.XmlConfigurator(ConfigFileExtension = "log4net", Watch = true)],
and by placing the log4net.config in C:\windows\system32\inetsrv,the error log is enabled and changing the line,
log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo(AppDomain.CurrentDomain.SetupInformation.ApplicationBase+"log4net.config"));
The IsDebugEnabled is true but i am not seeing any errors in the eventLog and its empty
DEV Environment :Windows 2003 ,log4net for .Net framework2.0 [1.2.10.0]
Thanks,
Vanitha Venkatasamy
XPAND Corporation.
[cid:image001.jpg@01CC5CC5.0C41E6E0]
________________________________
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.