logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zafer aydin <zafera...@hotmail.com>
Subject RE: RemotingAppender Problem
Date Tue, 24 Apr 2012 05:13:50 GMT

Hello Radovan;i solved the problem in an other way. Firstly, i load an almost empty xml configuration
file with the following line of code:log4net.Config.XmlConfigurator.Configure(new FileInfo(filename));After
that i could add the appender in the way that i described in my question. I think we must
first load an xml configuration to add loggers and appenders to loggers.I simply load a config
which has no appenders in it. Then, I added the appenders in code. I am using vs2008, .net
3.5 C#. The problem is now seen to be solved.Thanks for your answer.
Fer

From: raszka@hasam.cz
To: log4net-user@logging.apache.org
Subject: RE: RemotingAppender Problem
Date: Mon, 23 Apr 2012 10:37:22 +0000









You must call Configure method. Here is example with file appender - rewrite it as needed

 
log4net.Appender.RollingFileAppender fa =
new log4net.Appender.RollingFileAppender(); //create appender
fa.AppendToFile = true; // set options
fa.DatePattern = ".yyyy-MM-dd.lo\\g";
fa.File = System.IO.Path.GetTempPath() + filename;
fa.Layout = new log4net.Layout.PatternLayout("%date{dd-MM HH:mm:ss,fff} [%level] %message
%n");
fa.RollingStyle = log4net.Appender.RollingFileAppender.RollingMode.Date;
fa.Threshold = log4net.Core.Level.Debug;
fa.StaticLogFileName = false;
fa.ActivateOptions(); // activate options
log4net.Config.BasicConfigurator.Configure(fa); //configure logging system
 
Radovan Raszka





Od: zafer aydin [mailto:zaferaydn@hotmail.com] 

Odesláno: 19. dubna 2012 11:05

Komu: log4net-user@logging.apache.org

Předmět: FW: RemotingAppender Problem





Hello,



i need to add remoting appenders to my logger to enable to send logs to multiple remoting
listeners.
To achive this, i tried following sample in my code. But it doesnt work:




            ILog log = LogManager.GetLogger("logName");
            Repository.Hierarchy.Logger l = (Repository.Hierarchy.Logger)log.Logger;
            // set level
            l.Level = l.Hierarchy.LevelMap["ALL"];
            // create appander
            Appender.RemotingAppender remotingAppender = new Appender.RemotingAppender();
            remotingAppender.Name = "remotingAppender";
          & nbsp; remotingAppender.Sink = "tcp://localhost:8085/LoggingSink";
            remotingAppender.Lossy = false;
            remotingAppender.BufferSize = 1;            
            // create pattern
            log4net.Layout.PatternLayout layout = new log4net.Layout.PatternLayout();
            layout.ConversionPattern = "%d [%thread] %-5p %c [%a] - %m [%line] [%M]%n";
            layout.ActivateOptions();



            remotingAppender.Layout = layout;
            remotingAppender.ActivateOptions();



            // add appender
            l.AddAppender(remotingAppender);



            // let the log send through remoting appender
            log.Warn("my warning");
            log.Error("my error");



Remember that when i use xml configuration file it works OK. However i need an implementation
in code.
Thanks.


Fer



 		 	   		  
Mime
View raw message