Ah-hah! I spent way too much time on this, unfortunately, but the answer is quite simple: You're using VB.NET. heh, sorry, I had to! No, seriously, the answer is really that your <appender-ref> tag is malformed.
You have: <appender-ref name="OtherFeedLog"/> Should be: <appender-ref ref="OtherFeedLog"/> That fixed it for me in my sample test with your code. -Chad -----Original Message----- From: Ronnie Hayden [mailto:[EMAIL PROTECTED] Sent: Sunday, May 30, 2004 11:43 PM To: Log4NET User Subject: RE: Independent FileAppenders I tried this. I am able to log to MainLog but not to OtherLog. But when I add the OtherLogAppender to root, I am able to log to both logs (unfortunately not independently). I placed a breakpoint in the Application_Start method, where I call DOMConfigurator.Configure(), and it always hits it. So that's also not a problem. I have included my code below. If anyone could please let me know what I am doing wrong, I would be very grateful. Please feel free to let me know if you have any questions regarding the code. Thanks, Ronnie. The log4net section of my web.config is as follows: <log4net debug="false"> <appender name="MainLog" type="log4net.Appender.FileAppender,log4net" > <param name="File" value="C:\\Logs\\MainLog.txt" /> <param name="AppendToFile" value="true" /> <layout type="log4net.Layout.PatternLayout,log4net"> <param name="ConversionPattern" value="%d %-5p %m%n" /> </layout> </appender> <appender name="OtherFeedLog" type="log4net.Appender.FileAppender,log4net" > <param name="File" value="C:\\Logs\\OtherFeedLog.txt" /> <param name="AppendToFile" value="true" /> <layout type="log4net.Layout.PatternLayout,log4net"> <param name="ConversionPattern" value="%d %-5p %m%n" /> </layout> </appender> <root> <level value="DEBUG" /> <appender-ref ref="MainLog" /> </root> <logger name="OtherLogger" additivity="false"> <level value="DEBUG"/> <appender-ref name="OtherFeedLog"/> </logger> </log4net> I declare the logs as follows (in VB .NET): Private oMainLog As ILog = LogManager.GetLogger("MainLog") Private oOtherLog As ILog = LogManager.GetLogger("OtherLogger") I log messages like this: oMainLog.Info("Main Message") oMainLog.Warn("Main Message") oMainLog.Debug("Main Message") oMainLog.Error("Main Message") oMainLog.Fatal("Main Message") oOtherLog.Info("Other Message") oOtherLog.Warn("Other Message") oOtherLog.Debug("Other Message") oOtherLog.Error("Other Message") oOtherLog.Fatal("Other Message") I configure the logs by using the following code in the Application_Start method in Global.asax.vb: log4net.Config.DOMConfigurator.Configure() --- Chad Myers <[EMAIL PROTECTED]> wrote: > Oops, I mean "have two different loggers log to two > different > independent log appenders". > > -Chad > > -----Original Message----- > From: Chad Myers [mailto:[EMAIL PROTECTED] > Sent: Saturday, May 29, 2004 9:11 AM > To: Log4NET User > Subject: RE: Independent FileAppenders > > What I was saying is that I have an app I'm > developing right now that > does exactly what you're trying to do, have two > different loggers log to > two different independent loggers (i.e. Logger1 goes > to foo.log and > Logger2 goes to bar.log) and it works just fine. > > I do it with a similar config to what you just > mentioned. > > Now, to answer your question... you can't get a > handle to appenders > (well, you can, but it's not intuitive and you > shouldn't need to do it > anyhow) like MainLog or OtherLog. All you need to > care about is the > loggers such as "DataLogger" and all the other > loggers under root. > > With that config, these two statements should work: > > ILog defaultLog = LogManager.GetLogger("Blah"); > ILog dataLog = LogManager.GetLogger("DataLogger"); > > defaultLog.Error("Test"); > dataLog.Error("Data Test"); > > After your app exits, you should notice that > MainLog.txt has "Test" in > it and OtherLog.txt has "Data Test" in it. > > -c > > -----Original Message----- > From: Ronnie Hayden [mailto:[EMAIL PROTECTED] > Sent: Saturday, May 29, 2004 3:45 AM > To: Log4NET User > Subject: RE: Independent FileAppenders > > Chad, > > I too was able to log to multiple files. The problem > arises when I need to log to two different files > seperately. That's why I believe it is not that > log4net is not able to access the file system. > > But I think I know what is causing the problem. If > my > log4net section in my web.config file looks like > this: > > <log4net debug="false"> > <appender name="MainLog" > type="log4net.Appender.FileAppender,log4net" > > <param name="File" > value="C:\\Logs\\MainLog.txt" > /> > <param name="AppendToFile" value="true" /> > <layout > type="log4net.Layout.PatternLayout,log4net"> > <param name="ConversionPattern" value="%d > %-5p > %m%n" /> > </layout> > </appender> > <appender name="OtherLog" > type="log4net.Appender.FileAppender,log4net" > > <param name="File" > value="C:\\Logs\\OtherLog.txt" /> > <param name="AppendToFile" value="true" /> > <layout > type="log4net.Layout.PatternLayout,log4net"> > <param name="ConversionPattern" value="%d > %-5p > %m%n" /> > </layout> > </appender> > <root> > <level value="DEBUG"/> > <appender-ref name="MainLog"/> > </root> > <logger name="DataLogger" additivity="false"> > <level value="DEBUG"/> > <appender-ref name="OtherLog"/> > </logger> > </log4net> > > Assume I have a class called Logger, how do I get a > handle to MainLog and OtherLog. So I could invoke a > method (either Debug, Error, Fatal etc.) on each > object. For example in my Logger class I could type > oMainLog.Fatal("My Fatal Message") which would write > to C:\Logs\MainLog.txt, since oMainLog has a > reference > to the MainLog Appender. > > Thanks a lot. > > Ronnie. > > --- Chad Myers <[EMAIL PROTECTED]> wrote: > > I currently have an application (non-ASP.NET) that > > logs to multiple > > files and I use essentially the same type of > config > > file that I posted > > to you as an example and you posted back. > > > > It works, I know it does because I use it every > day. > > > > This is what makes me think that it has something > to > > do with either a.) > > ASP.NET or b.) The way you're using it from > ASP.NET > > or c.) Some type of > > permissions thing. > > > > Unfortunately I don't have time today to create a > > sample ASP.NET project > > to test this, but my guess is that other people > are > > doing similar things > > so I'm confident that this is possible from > ASP.NET. > > > > -Chad > > > > -----Original Message----- > > From: Ronnie Hayden > [mailto:[EMAIL PROTECTED] > > Sent: Friday, May 28, 2004 12:10 AM > > To: Log4NET User > > Subject: RE: Independent FileAppenders > > > > Chad, > > > > Putting DOMConfigurator.Configure() in the > > Application_Start initialized log4net before I > > changed > > the log4net section in the web.config file. So, I > > doubt this is an issue. > > > > Could you please create (or send one that is > already > > created) a Console Application that logs to two > > files > > seperately, and uses a Configuration file to > > configure > > log4net. > > > > Thanks, > > > > Ron. > > > > > > --- Chad Myers <[EMAIL PROTECTED]> wrote: > > > Your log4net config looks right, so other than > > that > > > it's an OS or > > > ASP.NET config issue or perhaps your code or > > > something. > > > > > > I'm not too familiar with logging from ASP.NET > > apps > > > as I haven't had to > > > do it yet, but perhaps putting the > > > DOMConfigurator.Configure() call in > > > the Application_Start might not be the best > thing > > to > > > do. Perhaps it's > > > not initializing log4net properly in time? > > > > > > You might try looking at the [assembly:] > > attributes > > > for Log4net to > > > initialize when the assembly is loaded? > > > > > > -Chad > > > > > > -----Original Message----- > > > From: Ronnie Hayden > > [mailto:[EMAIL PROTECTED] > > > Sent: Thursday, May 27, 2004 9:11 PM > > > To: Log4NET User > > > Subject: RE: Independent FileAppenders > === message truncated === __________________________________ Do you Yahoo!? Friends. Fun. Try the all-new Yahoo! Messenger. http://messenger.yahoo.com/
