logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Radovan Raszka <ras...@hasam.cz>
Subject RE: RemotingAppender Problem
Date Mon, 23 Apr 2012 10:37:22 GMT
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