Return-Path: X-Original-To: apmail-logging-log4net-dev-archive@www.apache.org Delivered-To: apmail-logging-log4net-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 106F318E60 for ; Sun, 1 Nov 2015 18:06:28 +0000 (UTC) Received: (qmail 47738 invoked by uid 500); 1 Nov 2015 18:06:27 -0000 Delivered-To: apmail-logging-log4net-dev-archive@logging.apache.org Received: (qmail 47691 invoked by uid 500); 1 Nov 2015 18:06:27 -0000 Mailing-List: contact log4net-dev-help@logging.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Log4NET Dev" List-Id: Delivered-To: mailing list log4net-dev@logging.apache.org Received: (qmail 47682 invoked by uid 99); 1 Nov 2015 18:06:27 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 01 Nov 2015 18:06:27 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id BA2F22C1F51 for ; Sun, 1 Nov 2015 18:06:27 +0000 (UTC) Date: Sun, 1 Nov 2015 18:06:27 +0000 (UTC) From: "Dominik Psenner (JIRA)" To: log4net-dev@logging.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Closed] (LOG4NET-475) Cannot add appender in Log4net at runtime MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ 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(), "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)