logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Dejardin <pdejar...@factset.com>
Subject RE: Duplicate log entries with DLL/EXE combination
Date Fri, 27 Apr 2012 15:37:48 GMT
private static readonly ILog DebugLog = LogManager.GetLogger(typeof(<yourclass>));
^--- this is the typical usage

http://logging.apache.org/log4net/release/manual/configuration.html

try removing the RepositoryAttribute from each assembly

http://logging.apache.org/log4net/release/sdk/log4net.Config.RepositoryAttribute.html

if that doesn't work, try programmatically getting all appenders from the default repository
root logger. Shouldn't be duplicates, but I don't really know the internals of that.

Are you getting any output from log4net? (failed to configure or some such message)

-----Original Message-----
From: Kramer, Mat [mailto:MKramer@datasci.com] 
Sent: Friday, April 27, 2012 11:12 AM
To: Log4NET User
Subject: RE: Duplicate log entries with DLL/EXE combination

Paul,

Thanks for the response.

Each of the assemblies is configured via the following entries in the AssemblyInfo.cs file:

	[assembly: log4net.Config.Repository]
	[assembly: log4net.Config.XmlConfigurator(ConfigFile = "my-assembly-log4net.config")]

I've tried changing the "conversionPattern" to determine which appender definition is being
used.  It is always using the application's appender definition.  All output is going to the
output file defined there.

Any class that needs to log will have a static member like this:

	private static readonly ILog DebugLog = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

-Mat

-------
From: Paul Dejardin [mailto:pdejardin@factset.com] 
Sent: Friday, April 27, 2012 7:56 AM
To: Log4NET User
Subject: RE: Duplicate log entries with DLL/EXE combination

How are you configuring? (programmatically, custom attribute, etc.) My guess would be that
the 'DebugAppender' is being added twice (once in two separate repositories). You could use
the same Repository for both assemblies. How are you creating loggers in code?

-------
From: Kramer, Mat [mailto:MKramer@datasci.com] 
Sent: Thursday, April 26, 2012 7:02 PM
To: log4net-user@logging.apache.org
Subject: Duplicate log entries with DLL/EXE combination

Hello,

We have a .NET executable and a DLL assembly that both use log4net.  One of the complications
is that the DLL is also called from an unmanaged C++ application and we want logging to work
in that setting.  Our current solution works, but I get many duplicate log entries when I
am running the .NET EXE with the .NET DLL.  The configurations are below.  Any ideas for
how to fix this?  I have to admit I don't really understand how it works now.

Thanks!

Application configuration

<log4net>

  <appender name="DebugAppender" type="log4net.Appender.RollingFileAppender">
    <file value="log-file-fauxnemah.txt" />
    <appendToFile value="true" />
    <rollingStyle value="Size" />
    <maxSizeRollBackups value="10" />
    <maximumFileSize value="50MB" />
    <staticLogFileName value="true" />
    <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date %7level [%2thread] %message%newline" />
    </layout>
  </appender>

  <root>
    <level value="ALL" />
    <appender-ref ref="DebugAppender" />
  </root>

</log4net>

DLL configuration

<log4net>

  <appender name="DebugAppender" type="log4net.Appender.RollingFileAppender">
    <file value="TruSense//log-file-trusenseP3P.txt" />
    <appendToFile value="true" />
    <rollingStyle value="Size" />
    <maxSizeRollBackups value="10" />
    <maximumFileSize value="50MB" />
    <staticLogFileName value="true" />
    <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date %7level [%2thread] %message%newline" />
    </layout>
  </appender>

  <root>
    <level value="ALL" />
    <appender-ref ref="DebugAppender" />
  </root>

  <logger name="DSI.DACSS.Transformers.FahiTransformer" additivity="false">
    <level value="NONE" />
  </logger>

  <logger name="DSI.DACSS.Framework.Logger.SystemLogger" additivity="false">
    <level value="ALL" />
    <appender-ref ref="DebugAppender" />
  </logger>

</log4net>


-Mat


Mime
View raw message