[prev in list] [next in list] [prev in thread] [next in thread] 

List:       log4net-dev
Subject:    [jira] [Created] (LOG4NET-475) Cannot add appender in Log4net at runtime
From:       "Mark (JIRA)" <jira () apache ! org>
Date:       2015-09-17 13:53:05
Message-ID: JIRA.12875363.1442497975000.893.1442497985729 () Atlassian ! JIRA
[Download RAW message or body]

Mark created LOG4NET-475:
----------------------------

             Summary: 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
            Priority: Blocker


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(), \
"TestLogFolder");  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
(v6.3.4#6332)


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic