Re: EventLog Fun Continued.
This code creates and writes to the appropriate custom event log area when I'm logged on as an Administrator on a Windows XP box stepping through a ConsoleApplication project in VS2008: class Program { private static EventLogAppender _eventLogAppender; static void Main(string[] args) { LogLog.InternalDebugging = true; LogLog.EmitInternalMessages = true; ConfigureEventLogAppender("ApplicationName", "LogName"); ILog log = LogManager.GetLogger(typeof(Program)); // first entry: normal case log.Debug("Hello World"); // second entry: also write an EventID var loggingEvent = new LoggingEvent( typeof(Program), log.Logger.Repository, log.Logger.Name, Level.Debug, "Hello World With EventId", null); loggingEvent .Properties["EventID"] = 42; log.Logger.Log(loggingEvent ); } public static void ConfigureEventLogAppender(string appName, string logName) { _eventLogAppender = new EventLogAppender(); _eventLogAppender.ApplicationName = appName; _eventLogAppender.Layout = new SimpleLayout(); _eventLogAppender.LogName = logName; _eventLogAppender.Threshold = Level.All; _eventLogAppender.ActivateOptions(); BasicConfigurator.Configure(_eventLogAppender); } } Note the casing of "EventID" and that its being attached to LoggingEvent's Properties bag and not to the more general ThreadContext. - Original Message From: James Green To: Log4NET User Sent: Friday, June 19, 2009 10:24:14 AM Subject: EventLog Fun Continued. Hi All, I'm still at a total loss as to how to get log4net successfully writing to a custom event log, writing to the Application event log is working exactly as expected. I have started using the IEventIDLog extension in order to pass over event IDs to the log messages to see if this makes any difference. I've looked over google a lot over the last couple of days and have tried everything I have found in terms of suggestions. The most recent one being this: http://www.mail-archive.com/log4net-user@logging.apache.org/msg02396.htm l Which talks of the same error I'm seeing in the application log that I mentioned before: I try to write to MyLog and this is entered into the Application log: The description for Event ID ( 0 ) in Source ( MyFirstApp ) cannot be found. The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. You may be able to use the /AUXSOURCE= flag to retrieve this description; see Help and Support for details. The following information is part of the event: 2009-06-19 12:11:27,234 14 INFO Logging.TestHarness.vshost.exe (line: 220) Logging.TestHarness.LogEntryCreator - Message number 71 System.Exception I think tried this suggestion: ILog logger = LogManager.GetLogger(sender); log4net.ThreadContext.Properties["EventID"] = 12; logger.Info(0,message); Which didn't make any difference. I have checked over the Sources key entries being created in the registery and all seems to be correct in there as well. I just never see *anything* making it into the MyLog event log. I've probably got another 2 hours left to use on this before I have to move onto other work which is incredibly frustrating as I will leave behind a 'buggy' half finished wrapper. Any input would be much appreciated. :| James
RE: Mystery concerning configuration SOLVED.
Actually, the file attribute on the node is processed by the .NET framework as a redirection to the given file. The attribute tells .NET to look for the actual definition of the section in the given file. log4net should be oblivious to this but it is not. The behavior seen is that log4net does read its configuration information from the specified file *but* it doesn't recognize those standard XML tags we log4net users have come to know and love. All it recognizes is . Of course, one could work around this--no functionality is prevented by this behavior--but it is rather awkward and unfriendly to work that way (especially if you're trying to do something like use schema directives for "intellisense"-like help). It is also much more readable to use the standard log4net schema and understandable to people who come onboard the project from other projects which have also used log4net. The take-away from this experience for me is that web.config redirections do not work nicely for log4net configuration. Though one can make them work, they exact a penalty. Better it is to just directly name that separate log4net config file when one initializes log4net. BTW, the best "intellisense" log4net schema I have found so far is from csharptest.net and is expressed as follows: http://csharptest.net/downloads/schema/lo g4net.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";> If there is another one better, I would like to hear about it. Specifically, it would be nice if I could find such a schema at logging.apache.org ! == Eric == From: Ron Grabowski [mailto:rongrabow...@yahoo.com] Sent: Friday, June 19, 2009 1:49 PM To: Log4NET User Subject: Re: Mystery concerning configuration SOLVED. Log4net doesn't process the file attribute. I'm not sure how you're using it. These two nodes are processed identically during configuration: From: Eric Chamberlain To: Log4NET User Sent: Friday, June 19, 2009 12:56:34 PM Subject: RE: Mystery concerning configuration SOLVED. I have discovered the source of the problem. We had split out the configuration from the web.config but with a redirection left inside the web.config of the form: The file at the end was of the correct syntax and could be used by log4net but only to the extent that we used the elements. I have modified the program to initialized log4net directly from the split-out file and it works with full syntactical support. Go figure, eh? == Eric == From: Eric Chamberlain To: log4net-user@logging.apache.org Sent: Thursday, June 18, 2009 6:41:51 PM Subject: Mystery concerning configuration Greetings all, I have an appender which works fine if specified with generic XML but not when specified with conventional log4net terms in the configuration. Examples should help: The following works: But the following does *not* work. It fails to initialize (I turned on the log4net debugging to see it). It appears that log4net initialization does not recognized its own XML schema. How is that possible? __ Eric Chamberlain
Re: Getting AdoNetAppender parameters using Log4Net API
Surprisingly the parameters collection isn't exposed publicly so you'd have to extend the built-in AdoNetAppender and expose them: public class AdoNetAppender2 : AdoNetAppender { public AdoNetAppenderParameter[] GetParameters() { return m_parameters.Cast().ToArray(); } } Then you can ask the repository for all the AdoNetAppender2 appenders and inspect their values: var repository = LogManager.GetRepository(); foreach (var appender in repository.GetAppenders()) { var adoNetAppender = appender as AdoNetAppender2; if (adoNetAppender != null) { foreach (var parameter in adoNetAppender.GetParameters()) { // parameter.ParameterName; } } } From: Cankut Eskin To: Log4NET User Sent: Friday, June 19, 2009 1:13:13 PM Subject: Getting AdoNetAppender parameters using Log4Net API Hello, I've defined some extra parameters for AdoNetAppender in log4net config file. Everything works fine. Here is one of my extra parameters defined: I wonder if there is some way in Log4Net API to get information about the parameters defined for AdoNetAppender in the config file. Any help will be appreciated. Regards, Cankut
Re: Mystery concerning configuration SOLVED.
Log4net doesn't process the file attribute. I'm not sure how you're using it. These two nodes are processed identically during configuration: From: Eric Chamberlain To: Log4NET User Sent: Friday, June 19, 2009 12:56:34 PM Subject: RE: Mystery concerning configuration SOLVED. I have discovered the source of the problem. We had split out the configuration from the web.config but with a redirection left inside the web.config of the form: The file at the end was of the correct syntax and could be used by log4net but only to the extent that we used the elements. I have modified the program to initialized log4net directly from the split-out file and it works with full syntactical support. Go figure, eh? == Eric == From:Eric Chamberlain To: log4net-user@logging.apache.org Sent: Thursday, June 18, 2009 6:41:51 PM Subject: Mystery concerning configuration Greetings all, I have an appender which works fine if specified with generic XML but not when specified with conventional log4net terms in the configuration. Examples should help: The following works: But the following does *not* work. It fails to initialize (I turned on the log4net debugging to see it). It appears that log4net initialization does not recognized its own XML schema. How is that possible? __ Eric Chamberlain
Re: unsubscribe
I think you need to send an email to a special unsubscribe address, not just a subject with unsubscribe as the subject. - Original Message From: Laurence Hunter To: Log4NET User Sent: Friday, June 19, 2009 12:51:17 PM Subject: unsubscribe unsubscribe
Getting AdoNetAppender parameters using Log4Net API
Hello, I've defined some extra parameters for AdoNetAppender in log4net config file. Everything works fine. Here is one of my extra parameters defined: I wonder if there is some way in Log4Net API to get information about the parameters defined for AdoNetAppender in the config file. Any help will be appreciated. Regards, Cankut
RE: Mystery concerning configuration SOLVED.
I have discovered the source of the problem. We had split out the configuration from the web.config but with a redirection left inside the web.config of the form: The file at the end was of the correct syntax and could be used by log4net but only to the extent that we used the elements. I have modified the program to initialized log4net directly from the split-out file and it works with full syntactical support. Go figure, eh? == Eric == From: Eric Chamberlain To: log4net-user@logging.apache.org Sent: Thursday, June 18, 2009 6:41:51 PM Subject: Mystery concerning configuration Greetings all, I have an appender which works fine if specified with generic XML but not when specified with conventional log4net terms in the configuration. Examples should help: The following works: But the following does *not* work. It fails to initialize (I turned on the log4net debugging to see it). It appears that log4net initialization does not recognized its own XML schema. How is that possible? __ Eric Chamberlain
unsubscribe
unsubscribe
unsubscribe
EventLog Fun Continued.
Hi All, I'm still at a total loss as to how to get log4net successfully writing to a custom event log, writing to the Application event log is working exactly as expected. I have started using the IEventIDLog extension in order to pass over event IDs to the log messages to see if this makes any difference. I've looked over google a lot over the last couple of days and have tried everything I have found in terms of suggestions. The most recent one being this: http://www.mail-archive.com/log4net-user@logging.apache.org/msg02396.htm l Which talks of the same error I'm seeing in the application log that I mentioned before: I try to write to MyLog and this is entered into the Application log: The description for Event ID ( 0 ) in Source ( MyFirstApp ) cannot be found. The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. You may be able to use the /AUXSOURCE= flag to retrieve this description; see Help and Support for details. The following information is part of the event: 2009-06-19 12:11:27,234 14 INFO Logging.TestHarness.vshost.exe (line: 220) Logging.TestHarness.LogEntryCreator - Message number 71 System.Exception I think tried this suggestion: ILog logger = LogManager.GetLogger(sender); log4net.ThreadContext.Properties["EventID"] = 12; logger.Info(0,message); Which didn't make any difference. I have checked over the Sources key entries being created in the registery and all seems to be correct in there as well. I just never see *anything* making it into the MyLog event log. I've probably got another 2 hours left to use on this before I have to move onto other work which is incredibly frustrating as I will leave behind a 'buggy' half finished wrapper. Any input would be much appreciated. :| James
RE: Event Log Weirdness.
Hi Again, I seem to have some info to work on. Trying to log into my custom event log has generated this in the Application event log: The description for Event ID ( 0 ) in Source ( MyFirstApp ) cannot be found. The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. You may be able to use the /AUXSOURCE= flag to retrieve this description; see Help and Support for details. The following information is part of the event: 2009-06-19 12:11:27,234 14 INFO Logging.TestHarness.vshost.exe (line: 220) Logging.TestHarness.LogEntryCreator - Message number 71 System.Exception: Arses! Hmm ... Any ideas would be great. Cheers, James.
RE: Event Log Weirdness.
Do you call ActivateOptions() when Threshold property is changed? Radovan Indeed I do ... public static void LogToEventLog(bool logToEventLog) { if (_eventLogAppender == null) return; if (logToEventLog) { _eventLogAppender.Threshold = Level.All; } else { _eventLogAppender.Threshold = Level.Off; } _eventLogAppender.ActivateOptions(); } This is being shown in my console window: log4net: EventLogAppender: Changing event source [MyFirstApp] from log [Applicat ion] to log [log4net] log4net: EventLogAppender: Source [MyFirstApp] is registered to log [log4net]
RE: Event Log Weirdness.
Do you call ActivateOptions() when Threshold property is changed? Radovan -Původní zpráva- Od: James Green [mailto:james.gr...@occam-dm.com] Odesláno: 19. června 2009 12:00 Komu: Log4NET User Předmět: RE: Event Log Weirdness. I should also point out that I know the Threshold is Off ... I have explicit methods that switch this on in order to prevent the event log from being swamped with log entries as the processes we run here could produce millions of logs a day ... Our default log destination is a SQL Database ... James. -Original Message- From: James Green Sent: 19 June 2009 10:51 To: Log4NET User Subject: Event Log Weirdness. Hi All, I'm just looking into an odd issue. I have an EventLogAppender being configured in C#. If I set this up to append to the "Application" log all is fine. However, when I ask it to create a custom event log called LogTest its not working as expected. Now the obvious thing is that the process doesn't have permissions ... it does. It created the new LogTest event log without problems but never writes to it ... >From reading the log4net docs it would seem that if I can create the log >(which I can) it stands to reason that it should also be able to write to it. This isn't an ASPNET process either, its a desktop windows application ... the C# that configures the LogAppender is: public static void ConfigureEventLogAppender(string appName, string logName) { PatternLayout layout = GetDefaultLayout(); _eventLogAppender = new EventLogAppender(); _eventLogAppender.ApplicationName = appName; _eventLogAppender.Layout = layout; _eventLogAppender.LogName = logName; _eventLogAppender.Threshold = Level.Off; _eventLogAppender.ActivateOptions(); BasicConfigurator.Configure(_eventLogAppender); } I can only assume that I'm missing something in this setup process but I can't see anything in the Xml versions of configuration that suggest what to do ... Cheers, James Green Technical Lead - Core Systems Occam DM Ltd Tel: +44(0)1761234716 scanned by MessageLabs [www.messagelabs.com] scanned by MessageLabs [www.messagelabs.com]
RE: Event Log Weirdness.
I should also point out that I know the Threshold is Off ... I have explicit methods that switch this on in order to prevent the event log from being swamped with log entries as the processes we run here could produce millions of logs a day ... Our default log destination is a SQL Database ... James. -Original Message- From: James Green Sent: 19 June 2009 10:51 To: Log4NET User Subject: Event Log Weirdness. Hi All, I'm just looking into an odd issue. I have an EventLogAppender being configured in C#. If I set this up to append to the "Application" log all is fine. However, when I ask it to create a custom event log called LogTest its not working as expected. Now the obvious thing is that the process doesn't have permissions ... it does. It created the new LogTest event log without problems but never writes to it ... >From reading the log4net docs it would seem that if I can create the log (which I can) it stands to reason that it should also be able to write to it. This isn't an ASPNET process either, its a desktop windows application ... the C# that configures the LogAppender is: public static void ConfigureEventLogAppender(string appName, string logName) { PatternLayout layout = GetDefaultLayout(); _eventLogAppender = new EventLogAppender(); _eventLogAppender.ApplicationName = appName; _eventLogAppender.Layout = layout; _eventLogAppender.LogName = logName; _eventLogAppender.Threshold = Level.Off; _eventLogAppender.ActivateOptions(); BasicConfigurator.Configure(_eventLogAppender); } I can only assume that I'm missing something in this setup process but I can't see anything in the Xml versions of configuration that suggest what to do ... Cheers, James Green Technical Lead - Core Systems Occam DM Ltd Tel: +44(0)1761234716 scanned by MessageLabs [www.messagelabs.com] scanned by MessageLabs [www.messagelabs.com]
Event Log Weirdness.
Hi All, I'm just looking into an odd issue. I have an EventLogAppender being configured in C#. If I set this up to append to the "Application" log all is fine. However, when I ask it to create a custom event log called LogTest its not working as expected. Now the obvious thing is that the process doesn't have permissions ... it does. It created the new LogTest event log without problems but never writes to it ... >From reading the log4net docs it would seem that if I can create the log (which I can) it stands to reason that it should also be able to write to it. This isn't an ASPNET process either, its a desktop windows application ... the C# that configures the LogAppender is: public static void ConfigureEventLogAppender(string appName, string logName) { PatternLayout layout = GetDefaultLayout(); _eventLogAppender = new EventLogAppender(); _eventLogAppender.ApplicationName = appName; _eventLogAppender.Layout = layout; _eventLogAppender.LogName = logName; _eventLogAppender.Threshold = Level.Off; _eventLogAppender.ActivateOptions(); BasicConfigurator.Configure(_eventLogAppender); } I can only assume that I'm missing something in this setup process but I can't see anything in the Xml versions of configuration that suggest what to do ... Cheers, James Green Technical Lead - Core Systems Occam DM Ltd Tel: +44(0)1761234716