Trying to set up an EXTREMELY SIMPLE event log feature... and failing terribly! Please help a newbie
Hi and thanks in advance for the help. I'm tearing my hair out over here trying to get this to work: a siple logger that writes to the application section of the event log. This is using log4net 1.2.10.0 Here is the app config: -- ?xml version=1.0 encoding=utf-8 ? configuration configSections section name=log4net type=log4net.Config.Log4NetConfigurationSectionHandler, log4net / /configSections log4net appender name=EventLogAppender type=log4net.Appender.EventLogAppender layout type=log4net.Layout.PatternLayout conversionPattern value=%date [%thread] %-5level %logger [%property{NDC}] - %message%newline / /layout /appender root level value=ALL / appender-ref ref=EventLogAppender / /root /log4net /configuration here is my code: log4net.Config.XmlConfigurator.Configure(); logger = LogManager.GetLogger(EventLogAppender); logger.Error(test); --- No errors, nothing happens! I notice that there are no appenders. nothing is written to the event log. I am tearing my hair out trying to figure out what is going on, can somebody help? -- View this message in context: http://www.nabble.com/Trying-to-set-up-an--EXTREMELY-SIMPLE-event-log-feature...-and-failing-terribly%21-Please-help-a-newbie-tp20448428p20448428.html Sent from the Log4net - Users mailing list archive at Nabble.com.
RE: Trying to set up an EXTREMELY SIMPLE event log feature... and failing terribly! Please help a newbie
Try using System.Configuration.IgnoreSectionHandler as the type for the configuration section handler. -Original Message- From: talktopete [mailto:[EMAIL PROTECTED] Sent: Tuesday, November 11, 2008 4:26 PM To: log4net-user@logging.apache.org Subject: RE: Trying to set up an EXTREMELY SIMPLE event log feature... and failing terribly! Please help a newbie This IS a console application, .net 3.5, and the app.config file is set to always copy on build, so that rules out number one. I ran the code you suggested, and yielded this information: --- Root Information: Name: log4net-default-repository Threshold: ALL Root Appenders: EventLogAppender, Hierarchy Appenders: Appender: EventLogAppender Type: log4net.Appender.EventLogAppender Loggers: EventLogAppender Additivity: True Level: null -- Does anything in there jump out at you, such as the Level perhaps? Francine Taylor wrote: You didn't mention what type of application this is being run from. I have two suggestions for error checking, don't know if they will help. The first is that if you are getting errors, you won't be able to see them unless you are running from a console application (or unless you set up a trace appender to grab the errors, I haven't done that so you'll have to google for it). This will tell you if the problem is with the error logging itself. The second is a method which will tell you how your log4net is configured. It's written in C#, so you may need to translate. This should tell you if it is your log4net configuration process which is going astray. public static string GetHierarchyInformation() { Hierarchy hier = (Hierarchy)LogManager.GetRepository(); StringBuilder sb = new StringBuilder(); // first, look for it in the root sb.AppendLine(Root Information:); sb.Append( Name: + hier.Name); sb.AppendLine( Threshold: + hier.Threshold.ToString()); sb.Append( Root Appenders: ); foreach (IAppender a in hier.Root.Appenders) { sb.Append(a.Name + , ); } sb.AppendLine(); sb.AppendLine(Hierarchy Appenders:); foreach (IAppender a in hier.GetAppenders()) { sb.AppendLine(FormatAppenderLine(a)); } sb.AppendLine(Loggers:); foreach (ILogger l in hier.GetCurrentLoggers()) { Logger log = (Logger)l; sb.Append(+ log.Name); sb.Append( Additivity: + log.Additivity.ToString()); sb.Append( Level: ); if (log.Level == null) { sb.Append(null); } else { sb.Append(log.Level.ToString()); } sb.AppendLine(); foreach (IAppender appender in log.Appenders) { sb.AppendLine(FormatAppenderLine(appender)); } } return sb.ToString(); } private static string FormatAppenderLine(IAppender appender) { StringBuilder sb2 = new StringBuilder(); sb2.Append( Appender: + appender.Name); sb2.Append( Type: + appender.GetType().ToString()); if (appender is log4net.Appender.FileAppender) { FileAppender app = (FileAppender)appender; sb2.Append( File: + app.File); } else if (appender is log4net.Appender.RollingFileAppender) { RollingFileAppender app = (RollingFileAppender)appender; sb2.Append( File: + app.File); } else if (appender is log4net.Appender.SmtpAppender) { SmtpAppender app = (SmtpAppender)appender; sb2.Append( To: + app.To); } return sb2.ToString(); } -Original Message- From: talktopete [mailto:[EMAIL PROTECTED] Sent: Tuesday, November 11, 2008 1:34 PM To: log4net-user@logging.apache.org Subject: Trying to set up an EXTREMELY SIMPLE event log feature... and failing terribly! Please help a newbie Hi and thanks in advance for the help. I'm tearing my hair out over here trying to get this to work: a siple logger that writes to the application section of the event log. This is using log4net 1.2.10.0 Here is the app config: -- ?xml version=1.0 encoding=utf-8 ? configuration configSections section name=log4net type=log4net.Config.Log4NetConfigurationSectionHandler, log4net / /configSections log4net appender name=EventLogAppender type=log4net.Appender.EventLogAppender layout
RE: Trying to set up an EXTREMELY SIMPLE event log feature... and failing terribly! Please help a newbie
I set my config section handler to: configSections section name=log4net type=System.Configuration.IgnoreSectionHandler / /configSections and it gave the exact same behavior, no error messages, and nothing in the event log.:confused: gary.grubbs wrote: Try using System.Configuration.IgnoreSectionHandler as the type for the configuration section handler. -Original Message- From: talktopete [mailto:[EMAIL PROTECTED] Sent: Tuesday, November 11, 2008 4:26 PM To: log4net-user@logging.apache.org Subject: RE: Trying to set up an EXTREMELY SIMPLE event log feature... and failing terribly! Please help a newbie This IS a console application, .net 3.5, and the app.config file is set to always copy on build, so that rules out number one. I ran the code you suggested, and yielded this information: --- Root Information: Name: log4net-default-repository Threshold: ALL Root Appenders: EventLogAppender, Hierarchy Appenders: Appender: EventLogAppender Type: log4net.Appender.EventLogAppender Loggers: EventLogAppender Additivity: True Level: null -- Does anything in there jump out at you, such as the Level perhaps? Francine Taylor wrote: You didn't mention what type of application this is being run from. I have two suggestions for error checking, don't know if they will help. The first is that if you are getting errors, you won't be able to see them unless you are running from a console application (or unless you set up a trace appender to grab the errors, I haven't done that so you'll have to google for it). This will tell you if the problem is with the error logging itself. The second is a method which will tell you how your log4net is configured. It's written in C#, so you may need to translate. This should tell you if it is your log4net configuration process which is going astray. public static string GetHierarchyInformation() { Hierarchy hier = (Hierarchy)LogManager.GetRepository(); StringBuilder sb = new StringBuilder(); // first, look for it in the root sb.AppendLine(Root Information:); sb.Append( Name: + hier.Name); sb.AppendLine( Threshold: + hier.Threshold.ToString()); sb.Append( Root Appenders: ); foreach (IAppender a in hier.Root.Appenders) { sb.Append(a.Name + , ); } sb.AppendLine(); sb.AppendLine(Hierarchy Appenders:); foreach (IAppender a in hier.GetAppenders()) { sb.AppendLine(FormatAppenderLine(a)); } sb.AppendLine(Loggers:); foreach (ILogger l in hier.GetCurrentLoggers()) { Logger log = (Logger)l; sb.Append(+ log.Name); sb.Append( Additivity: + log.Additivity.ToString()); sb.Append( Level: ); if (log.Level == null) { sb.Append(null); } else { sb.Append(log.Level.ToString()); } sb.AppendLine(); foreach (IAppender appender in log.Appenders) { sb.AppendLine(FormatAppenderLine(appender)); } } return sb.ToString(); } private static string FormatAppenderLine(IAppender appender) { StringBuilder sb2 = new StringBuilder(); sb2.Append( Appender: + appender.Name); sb2.Append( Type: + appender.GetType().ToString()); if (appender is log4net.Appender.FileAppender) { FileAppender app = (FileAppender)appender; sb2.Append( File: + app.File); } else if (appender is log4net.Appender.RollingFileAppender) { RollingFileAppender app = (RollingFileAppender)appender; sb2.Append( File: + app.File); } else if (appender is log4net.Appender.SmtpAppender) { SmtpAppender app = (SmtpAppender)appender; sb2.Append( To: + app.To); } return sb2.ToString(); } -Original Message- From: talktopete [mailto:[EMAIL PROTECTED] Sent: Tuesday, November 11, 2008 1:34 PM To: log4net-user@logging.apache.org Subject: Trying to set up an EXTREMELY SIMPLE event log feature... and failing terribly! Please help a newbie Hi and thanks in advance for the help. I'm tearing my hair out over here trying to get this to work: a siple logger that writes to the application section of the event log. This is using log4net 1.2.10.0 Here is the app config:
RE: Trying to set up an EXTREMELY SIMPLE event log feature... and failing terribly! Please help a newbie
I tried your code, as originally posted, locally and it works with the addition of the declaration of the logger variable (ILog logger;). The message should output to the Application log. Couple of questions: Are you expecting it to create and log to a EventLogAppender log? Have you tried running this locally and checking your local event log? If no, have you validated that security is correctly set/configured to allow you to write to the event log of the remote machine? -Original Message- From: talktopete [mailto:[EMAIL PROTECTED] Sent: Tuesday, November 11, 2008 5:43 PM To: log4net-user@logging.apache.org Subject: RE: Trying to set up an EXTREMELY SIMPLE event log feature... and failing terribly! Please help a newbie I set my config section handler to: configSections section name=log4net type=System.Configuration.IgnoreSectionHandler / /configSections and it gave the exact same behavior, no error messages, and nothing in the event log.:confused: gary.grubbs wrote: Try using System.Configuration.IgnoreSectionHandler as the type for the configuration section handler. -Original Message- From: talktopete [mailto:[EMAIL PROTECTED] Sent: Tuesday, November 11, 2008 4:26 PM To: log4net-user@logging.apache.org Subject: RE: Trying to set up an EXTREMELY SIMPLE event log feature... and failing terribly! Please help a newbie This IS a console application, .net 3.5, and the app.config file is set to always copy on build, so that rules out number one. I ran the code you suggested, and yielded this information: --- Root Information: Name: log4net-default-repository Threshold: ALL Root Appenders: EventLogAppender, Hierarchy Appenders: Appender: EventLogAppender Type: log4net.Appender.EventLogAppender Loggers: EventLogAppender Additivity: True Level: null -- Does anything in there jump out at you, such as the Level perhaps? Francine Taylor wrote: You didn't mention what type of application this is being run from. I have two suggestions for error checking, don't know if they will help. The first is that if you are getting errors, you won't be able to see them unless you are running from a console application (or unless you set up a trace appender to grab the errors, I haven't done that so you'll have to google for it). This will tell you if the problem is with the error logging itself. The second is a method which will tell you how your log4net is configured. It's written in C#, so you may need to translate. This should tell you if it is your log4net configuration process which is going astray. public static string GetHierarchyInformation() { Hierarchy hier = (Hierarchy)LogManager.GetRepository(); StringBuilder sb = new StringBuilder(); // first, look for it in the root sb.AppendLine(Root Information:); sb.Append( Name: + hier.Name); sb.AppendLine( Threshold: + hier.Threshold.ToString()); sb.Append( Root Appenders: ); foreach (IAppender a in hier.Root.Appenders) { sb.Append(a.Name + , ); } sb.AppendLine(); sb.AppendLine(Hierarchy Appenders:); foreach (IAppender a in hier.GetAppenders()) { sb.AppendLine(FormatAppenderLine(a)); } sb.AppendLine(Loggers:); foreach (ILogger l in hier.GetCurrentLoggers()) { Logger log = (Logger)l; sb.Append(+ log.Name); sb.Append( Additivity: + log.Additivity.ToString()); sb.Append( Level: ); if (log.Level == null) { sb.Append(null); } else { sb.Append(log.Level.ToString()); } sb.AppendLine(); foreach (IAppender appender in log.Appenders) { sb.AppendLine(FormatAppenderLine(appender)); } } return sb.ToString(); } private static string FormatAppenderLine(IAppender appender) { StringBuilder sb2 = new StringBuilder(); sb2.Append( Appender: + appender.Name); sb2.Append( Type: + appender.GetType().ToString()); if (appender is log4net.Appender.FileAppender) { FileAppender app = (FileAppender)appender; sb2.Append( File: + app.File); } else if (appender is log4net.Appender.RollingFileAppender) { RollingFileAppender app = (RollingFileAppender)appender; sb2.Append( File: + app.File); } else if (appender is
Re: Trying to set up an EXTREMELY SIMPLE event log feature... and failing terribly! Please help a newbie
The first thing I would is to make sure log4net itself is working. Your config file runs correctly when I add a ConsoleAppender: ?xml version=1.0 encoding=utf-8 ? configuration configSections section name=log4net type=log4net.Config.Log4NetConfigurationSectionHandler, log4net / /configSections log4net appender name=EventLogAppender type=log4net.Appender.EventLogAppender layout type=log4net.Layout.SimpleLayout / /appender appender name=ConsoleAppender type=log4net.Appender.ConsoleAppender layout type=log4net.Layout.SimpleLayout / /appender root level value=ALL / appender-ref ref=EventLogAppender / appender-ref ref=ConsoleAppender / /root /log4net /configuration I can also see the entries in the Event Log. Internal debugging: appSettings add key=log4net.Internal.Debug value=true / /appSettings didn't show any problems. Do you get an exceptions when internal debugging is turned on? From what I can tell it looks like there's something wrong with the machine its running on. - Original Message From: talktopete [EMAIL PROTECTED] To: log4net-user@logging.apache.org Sent: Tuesday, November 11, 2008 4:34:20 PM Subject: Trying to set up an EXTREMELY SIMPLE event log feature... and failing terribly! Please help a newbie Hi and thanks in advance for the help. I'm tearing my hair out over here trying to get this to work: a siple logger that writes to the application section of the event log. This is using log4net 1.2.10.0 Here is the app config: -- ?xml version=1.0 encoding=utf-8 ? configuration configSections section name=log4net type=log4net.Config.Log4NetConfigurationSectionHandler, log4net / /configSections log4net appender name=EventLogAppender type=log4net.Appender.EventLogAppender layout type=log4net.Layout.PatternLayout conversionPattern value=%date [%thread] %-5level %logger [%property{NDC}] - %message%newline / /layout /appender root level value=ALL / appender-ref ref=EventLogAppender / /root /log4net /configuration here is my code: log4net.Config.XmlConfigurator.Configure(); logger = LogManager.GetLogger(EventLogAppender); logger.Error(test); --- No errors, nothing happens! I notice that there are no appenders. nothing is written to the event log. I am tearing my hair out trying to figure out what is going on, can somebody help? -- View this message in context: http://www.nabble.com/Trying-to-set-up-an--EXTREMELY-SIMPLE-event-log-feature...-and-failing-terribly%21-Please-help-a-newbie-tp20448428p20448428.html Sent from the Log4net - Users mailing list archive at Nabble.com.
Re: Trying to set up an EXTREMELY SIMPLE event log feature... and failing terribly! Please help a newbie
By golly, you got it!!! By changing my layout to log4net.Layout.SimpleLayout, it started working! The problem was with the layout format: -- %date [%thread] %-5level %logger [%property{NDC}] - %message%newline -- something in there caused the logger to fail. What is annoying is how silently it failed, I wish there was an option to make log4net throw verbose, easy-to-understand exceptions! I got the layout string from various examples on the google. Go figure someone posted code that fails... Ron Grabowski wrote: The first thing I would is to make sure log4net itself is working. Your config file runs correctly when I add a ConsoleAppender: ?xml version=1.0 encoding=utf-8 ? configuration configSections section name=log4net type=log4net.Config.Log4NetConfigurationSectionHandler, log4net / /configSections log4net appender name=EventLogAppender type=log4net.Appender.EventLogAppender layout type=log4net.Layout.SimpleLayout / /appender appender name=ConsoleAppender type=log4net.Appender.ConsoleAppender layout type=log4net.Layout.SimpleLayout / /appender root level value=ALL / appender-ref ref=EventLogAppender / appender-ref ref=ConsoleAppender / /root /log4net /configuration I can also see the entries in the Event Log. Internal debugging: appSettings add key=log4net.Internal.Debug value=true / /appSettings didn't show any problems. Do you get an exceptions when internal debugging is turned on? From what I can tell it looks like there's something wrong with the machine its running on. - Original Message From: talktopete [EMAIL PROTECTED] To: log4net-user@logging.apache.org Sent: Tuesday, November 11, 2008 4:34:20 PM Subject: Trying to set up an EXTREMELY SIMPLE event log feature... and failing terribly! Please help a newbie Hi and thanks in advance for the help. I'm tearing my hair out over here trying to get this to work: a siple logger that writes to the application section of the event log. This is using log4net 1.2.10.0 Here is the app config: -- ?xml version=1.0 encoding=utf-8 ? configuration configSections section name=log4net type=log4net.Config.Log4NetConfigurationSectionHandler, log4net / /configSections log4net appender name=EventLogAppender type=log4net.Appender.EventLogAppender layout type=log4net.Layout.PatternLayout conversionPattern value=%date [%thread] %-5level %logger [%property{NDC}] - %message%newline / /layout /appender root level value=ALL / appender-ref ref=EventLogAppender / /root /log4net /configuration here is my code: log4net.Config.XmlConfigurator.Configure(); logger = LogManager.GetLogger(EventLogAppender); logger.Error(test); --- No errors, nothing happens! I notice that there are no appenders. nothing is written to the event log. I am tearing my hair out trying to figure out what is going on, can somebody help? -- View this message in context: http://www.nabble.com/Trying-to-set-up-an--EXTREMELY-SIMPLE-event-log-feature...-and-failing-terribly%21-Please-help-a-newbie-tp20448428p20448428.html Sent from the Log4net - Users mailing list archive at Nabble.com. -- View this message in context: http://www.nabble.com/Trying-to-set-up-an--EXTREMELY-SIMPLE-event-log-feature...-and-failing-terribly%21-Please-help-a-newbie-tp20448428p20451489.html Sent from the Log4net - Users mailing list archive at Nabble.com.