logging-log4net-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dominik Psenner (JIRA)" <j...@apache.org>
Subject [jira] [Closed] (LOG4NET-475) Cannot add appender in Log4net at runtime
Date Sun, 01 Nov 2015 18:06:27 GMT

     [ https://issues.apache.org/jira/browse/LOG4NET-475?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel

Dominik Psenner closed LOG4NET-475.
    Resolution: Fixed
      Assignee: Dominik Psenner

You should write the test such that it initializes the appender and tests its functionality
without requiring the entire framework to be loaded. Please send future questions to one of
the mailing lists mentioned at https://logging.apache.org/log4net/mail-lists.html

> Cannot add appender in Log4net at runtime
> -----------------------------------------
>                 Key: LOG4NET-475
>                 URL: https://issues.apache.org/jira/browse/LOG4NET-475
>             Project: Log4net
>          Issue Type: Bug
>          Components: Appenders
>    Affects Versions: 1.2.13
>         Environment: Windows, C#, Visual Studio unit testing
>            Reporter: Mark
>            Assignee: Dominik Psenner
>            Priority: Blocker
>              Labels: test
> I am trying to write a custom appender that rolls over daily, as well as on a size limit,
and cleans up after itself in the process. I wrote the implementation using the AppenderSkeleton
as a base class, then attempted to write a unit test to test the appender functionality. I
do the following:
>             DailyRollingFileAppender appender = new DailyRollingFileAppender();
>             appender.RollOverOnSize = true;
>             appender.RollOverDaily = true; //dont think I can test this
>             appender.MaxFileSizeBytes = 1024;
>             appender.RolloverDayCount = 1;
>             appender.RollOverOnSize = true;
>             appender.LoggingDirectory = Path.Combine(Directory.GetCurrentDirectory(),
>             appender.LogFileName = "TestLogFileName";
>             appender.DateTimeFormatString = "YYYY-MM-DD-hh-mm-ss";
>             appender.Cleanup = true;
>             appender.Layout = new PatternLayout();
>             appender.MaxNumberOfFiles = 10;
>             appender.Name = "testAppender";
>             //lets write some crappy log messages
>             byte[] bytes = new byte[1050];
>             Random rnd = new Random();
>             rnd.NextBytes(bytes);
>             ILog log = LogManager.GetLogger("LoggerName");
>             Logger logger = (Logger)log.Logger;
>             logger.AddAppender(appender);
>             logger.Log(Level.Info, Encoding.UTF8.GetString(bytes), new Exception());
>             logger.Log(Level.Info, Encoding.UTF8.GetString(bytes), null);
> The code is based on the only examples I can find of people adding appenders to loggers
at runtime, which you would want to do for a unit test. The issue is that the Logger instance
I get from the call to ILog.Logger in the code above as a collection of appenders of type
ReadOnlyAppenderCollection. The code silently consumes the exception it throws internally
and never actually adds the appender to the collection. Can/How do I add an appender to a
logger at runtime in the manner described above, so I can appropriately test that it functions.

This message was sent by Atlassian JIRA

View raw message