Tobias Schittkowski | 8 Oct 2009 12:34

Configuring log4net without xml in VB.NET

I want to share my code to configure the (excellent!) log4net logging system:

http://www.schittkowski.de/?q=node/25



- RollingFileAppender
- AdoNetAppender using Postgres
- ColoredConsoleAppender

Some feedback is welcome!

Regards,

Tobias
Wilco K | 8 Oct 2009 15:13
Picon
Favicon

Header in new file

LS,

Is it possible to log a header message to a new file (using the rollingfileappender)? (not a header before every log entry)
 
Grz

Deel je favoriete foto's online met Windows Live Photos
Roy Chastain | 9 Oct 2009 04:35

RE: Header in new file

It is possible.  Example below

		<appender name="RollingTrace" type="log4net.Appender.RollingFileAppender">
			<param name="File" value="${ALLUSERSPROFILE}\\Trace.txt" />
			<param name="AppendToFile" value="true" />
			<param name="MaxSizeRollBackups" value="4" />
			<param name="MaximumFileSize" value="500000" />
			<param name="RollingStyle" value="Size" />
			<param name="StaticLogFileName" value="true" />
			<param name="Threshold" value="TRACE" />
			<param name="PreserveLogFileNameExtension" value="true" />
			<layout type="log4net.Layout.DynamicPatternLayout">
				<param name="Header" value="%newline**** Trace Opened     Local: %date{yyyy-MM-dd HH:mm:ss.fff}    
UTC: %utcdate{yyyy-MM-dd HH:mm:ss.fff} ****%newline" />
				<param name="Footer" value="**** Trace Closed %date{yyyy-MM-dd HH:mm:ss.fff} ****%newline" />
				<param name="ConversionPattern" value="%d{dd HH:mm:ss.fff} [%4t] %P{instance}::%M - %m%n" />
			</layout>
		</appender>

Just FYI, this will not work out of the box.  The Header/Footer formatting will work, but the time will not
ever change with the release code.  I had to update some of the DynamicPatternLayout code to make it
re-evaluate the date/time for each file.

I am willing to share the changes, but I have NO IDEA how to use the source control product to create the
changes etc.

From: Wilco K [mailto:wilcok36 <at> hotmail.com] 
Sent: Thursday, October 08, 2009 09:13
To: log4net-user <at> logging.apache.org
Subject: Header in new file

LS,

Is it possible to log a header message to a new file (using the rollingfileappender)? (not a header
before every log entry)
 
Grz 
________________________________________
Deel je favoriete foto's online met Windows Live Photos

Ron Grabowski | 9 Oct 2009 05:45
Picon
Favicon

Re: Two assemblies using same Log4Net framework

The main application should configure log4net. The other libraries should just create logging
statements. You don't need to pass the repository between applications.

----- Original Message ----
From: Peter <peter_m <at> circle-consulting.co.nz>
To: log4net-user <at> logging.apache.org
Sent: Thu, September 24, 2009 10:11:37 PM
Subject: Two assemblies using same Log4Net framework

Hi

My main VB.NET application uses sets up and configures Log4Net.  It calls two 
or three other assemblies and I want to "pass a reference" to the main app's 
Log4Net instance to those assemblies so they log messages into the same log 
file and respect the same configuration settings.  Is it correct to do this:

In the main app I have the following method call to my assembly:

  SetLog(mLog.Logger.Repository)

Where "mLog" implements the ILog interface.

In the assembly the SetLog method is:

  Public Sub SetLog(ByVal Repository As log4net.Repository.ILoggerRepository)

    log4net.Config.BasicConfigurator.Configure(Repository)

    mLog = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod
().DeclaringType)

   End Sub

This seems to work OK but I'm unsure if it's a good thing to pass Repository's 
between assemblies in this way.

Any and all advice would be appreciated.

Wilco K | 9 Oct 2009 10:15
Picon
Favicon

RE: Header in new file

 
It looks there is no DynamicPatternLayout type in the log4net assembly.
Can you send me your working copy of it?
 
Thanks!
 
 
> Subject: RE: Header in new file
> Date: Thu, 8 Oct 2009 22:35:27 -0400
> From: Roy <at> roychastain.org
> To: log4net-user <at> logging.apache.org
>
> It is possible. Example below
>
> <appender name="RollingTrace" type="log4net.Appender.RollingFileAppender">
> <param name="File" value="${ALLUSERSPROFILE}\\Trace.txt" />
> <param name="AppendToFile" value="true" />
> <param name="MaxSizeRollBackups" value="4" />
> <param name="MaximumFileSize" value="500000" />
> <param name="RollingStyle" value="Size" />
> <param name="StaticLogFileName" value="true" />
> <param name="Threshold" value="TRACE" />
> <param name="PreserveLogFileNameExtension" value="true" />
> <layout type="log4net.Layout.DynamicPatternLayout">
> <param name="Header" value="%newline**** Trace Opened Local: %date{yyyy-MM-dd HH:mm:ss.fff} UTC: %utcdate{yyyy-MM-dd HH:mm:ss.fff} ****%newline" />
> <param name="Footer" value="**** Trace Closed %date{yyyy-MM-dd HH:mm:ss.fff} ****%newline" />
> <param name="ConversionPattern" value="%d{dd HH:mm:ss.fff} [%4t] %P{instance}::%M - %m%n" />
> </layout>
> </appender>
>
> Just FYI, this will not work out of the box. The Header/Footer formatting will work, but the time will not ever change with the release code. I had to update some of the DynamicPatternLayout code to make it re-evaluate the date/time for each file.
>
> I am willing to share the changes, but I have NO IDEA how to use the source control product to create the changes etc.
>
>
>
>
> From: Wilco K [mailto:wilcok36 <at> hotmail.com]
> Sent: Thursday, October 08, 2009 09:13
> To: log4net-user <at> logging.apache.org
> Subject: Header in new file
>
> LS,
>
> Is it possible to log a header message to a new file (using the rollingfileappender)? (not a header before every log entry)
>  
> Grz
> ________________________________________
> Deel je favoriete foto's online met Windows Live Photos

Lees je Het Net, KPN/Planet, Ziggo of XS4ALL-mail in Windows Live Hotmail
Roy Chastain | 9 Oct 2009 13:00

RE: Header in new file

Create a new module (I called mine DynamicPatternLayout) in the
src\layout directory.  Paste this code into it.
Build and use.  (As I recall that is all I did.)
(Code below has TABs in it for alignment.)

using System;
using System.Collections;
using System.IO;

using log4net.Core;
using log4net.Layout.Pattern;
using log4net.Util;

namespace log4net.Layout
{
	/// <summary>
	/// A flexible layout configurable with pattern string that
re-evaluates on each call.
	/// </summary>
	/// <remarks>
	/// <para>This class is built on <see
cref="PatternLayout"></see> and provides all the
	/// features and capabilites of PatternLayout.  PatternLayout is
a 'static' class
	/// in that its layout is done once at configuration time.  This
class will recreate
	/// the layout on each reference.</para>
	/// <para>On important difference between PatternLayout and
DynamicPatternLayout is the
	/// treatment of the Header and Foot parameters in the
configuration.  The Header and Footer
	/// parameters for DynamicPatternLayout must be syntactacly in
the form of a PatternString,
	/// but should not be marked as type log4net.Util.PatternString.
Doing so causes the
	/// pattern to be staticly converted at configuration tiame and
causes DynamicPatternLayout
	/// to perform the same as PatternLayout.</para>
	/// <para>Please see <see cref="PatternLayout"></see> for
complete documentation.</para>
	/// </remarks>
	class DynamicPatternLayout: PatternLayout
	{
		#region Member Variables

		/// <summary>
		/// The header PatternString
		/// </summary>
		private PatternString m_headerPatternString = new
PatternString("");

		/// <summary>
		/// The footer PatternString
		/// </summary>
		private PatternString m_footerPatternString  = new
PatternString("");

		#endregion

		#region Constructors

		/// <summary>
		/// Constructs a DynamicPatternLayout using the
DefaultConversionPattern
		/// </summary>
		/// <remarks>
		/// <para>
		/// The default pattern just produces the application
supplied message.
		/// </para>
		/// <para>
		/// Note to Inheritors: This constructor calls the
virtual method
		/// <see cref="CreatePatternParser"/>. If you override
this method be
		/// aware that it will be called before your is called
constructor.
		/// </para>
		/// <para>
		/// As per the <see cref="IOptionHandler"/> contract the
<see cref="ActivateOptions"/>
		/// method must be called after the properties on this
object have been
		/// configured.
		/// </para>
		/// </remarks>
		public DynamicPatternLayout()
			: base()
		{
		}

		/// <summary>
		/// Constructs a DynamicPatternLayout using the supplied
conversion pattern
		/// </summary>
		/// <param name="pattern">the pattern to use</param>
		/// <remarks>
		/// <para>
		/// Note to Inheritors: This constructor calls the
virtual method
		/// <see cref="CreatePatternParser"/>. If you override
this method be
		/// aware that it will be called before your is called
constructor.
		/// </para>
		/// <para>
		/// When using this constructor the <see
cref="ActivateOptions"/> method 
		/// need not be called. This may not be the case when
using a subclass.
		/// </para>
		/// </remarks>
		public DynamicPatternLayout (string pattern) 
			: base(pattern)
		{
		}

		#endregion

		#region Override implementation of LayoutSkeleton
		public override string Header
		{
			get
			{
				return m_headerPatternString.Format();
			}
			set
			{
				base.Header = value;
				m_headerPatternString = new
PatternString(value);
			}
		}		/* property DynamicPatternLayout Header
*/

		public override string Footer
		{
			get
			{
				return m_footerPatternString.Format();
			}
			set
			{
				base.Footer = value;
				m_footerPatternString = new
PatternString(value);
			}
		}		/* property DynamicPatternLayout Footer
*/
		#endregion
	}			/* class DynamicPatternLayout */
}				/* namespace log4net.Layout */

----------------------------------------------------------------------
Roy Chastain

-----Original Message-----
From: Wilco K [mailto:wilcok36 <at> hotmail.com] 
Sent: Friday, October 09, 2009 04:16
To: log4net-user <at> logging.apache.org
Subject: RE: Header in new file

 
It looks there is no DynamicPatternLayout type in the log4net assembly.
Can you send me your working copy of it?

Thanks!

 
> Subject: RE: Header in new file
> Date: Thu, 8 Oct 2009 22:35:27 -0400
> From: Roy <at> roychastain.org
> To: log4net-user <at> logging.apache.org
> 
> It is possible. Example below
> 
> <appender name="RollingTrace" 
> type="log4net.Appender.RollingFileAppender">
> <param name="File" value="${ALLUSERSPROFILE}\\Trace.txt" /> <param 
> name="AppendToFile" value="true" /> <param name="MaxSizeRollBackups" 
> value="4" /> <param name="MaximumFileSize" value="500000" /> <param 
> name="RollingStyle" value="Size" /> <param name="StaticLogFileName" 
> value="true" /> <param name="Threshold" value="TRACE" /> <param 
> name="PreserveLogFileNameExtension" value="true" /> <layout 
> type="log4net.Layout.DynamicPatternLayout">
> <param name="Header" value="%newline**** Trace Opened Local: 
> %date{yyyy-MM-dd HH:mm:ss.fff} UTC: %utcdate{yyyy-MM-dd HH:mm:ss.fff} 
> ****%newline" /> <param name="Footer" value="**** Trace Closed 
> %date{yyyy-MM-dd HH:mm:ss.fff} ****%newline" /> <param 
> name="ConversionPattern" value="%d{dd HH:mm:ss.fff} [%4t] 
> %P{instance}::%M - %m%n" /> </layout> </appender>
> 
> Just FYI, this will not work out of the box. The Header/Footer
formatting will work, but the time will not ever change with the release
code. I had to update some of the DynamicPatternLayout code to make it
re-evaluate the date/time for each file.
> 
> I am willing to share the changes, but I have NO IDEA how to use the
source control product to create the changes etc.
> 
> 
> 
> 
> From: Wilco K [mailto:wilcok36 <at> hotmail.com]
> Sent: Thursday, October 08, 2009 09:13
> To: log4net-user <at> logging.apache.org
> Subject: Header in new file
> 
> LS,
> 
> Is it possible to log a header message to a new file (using the 
> rollingfileappender)? (not a header before every log entry)
>  
> Grz
> ________________________________________
> Deel je favoriete foto's online met Windows Live Photos

________________________________

Lees je Het Net, KPN/Planet, Ziggo of XS4ALL-mail in Windows Live
Hotmail
<http://www.microsoft.com/netherlands/windowslive/Views/productDetail.as
px?product=Hotmail&openVideo=5> 

SteveClay | 12 Oct 2009 12:09

Debugging from Visual Studio 2005: log statements in dlls don't work


When debugging tests from Visual Studio 2005 the log statements in my dlls
don't work.

The test project has a config xml file with the log4net extension.
Each test is prefixed with [TestMethod] and I use the right click 'Test with
...debugger' option.

Then each dll has a statement like this in its AssemblyInfo.cs:
[assembly: log4net.Config.XmlConfigurator(ConfigFileExtension = "log4net",
Watch = true)]

A log file does get created but it just says 'Log file start' / Log file
end' ..there are many log statements in the executed code which should write
to the log.

Please can someone tell me how can I configure VS or my test project or the
other projects so that logging works when running in debug mode?

--

-- 
View this message in context: http://www.nabble.com/Debugging-from-Visual-Studio-2005%3A-log-statements-in-dlls-don%27t-work-tp25853273p25853273.html
Sent from the Log4net - Users mailing list archive at Nabble.com.

Michael Hablich | 12 Oct 2009 13:06

Signing the log4net.dll with a digital signature

Hello,

 

is it allowed to sign the log4net.dll with my own digital signature?

 

Thanks in advance,

Michael

 

Karim Bourouba | 12 Oct 2009 13:50
Picon
Favicon

RE: Signing the log4net.dll with a digital signature

I would say yes, it is. But I am not sure as to why you would want to do this?



 
From: m.hablich <at> tricentis.com
To: log4net-user <at> logging.apache.org
Date: Mon, 12 Oct 2009 13:06:34 +0200
Subject: Signing the log4net.dll with a digital signature

.ExternalClass p.ecxMsoNormal, .ExternalClass li.ecxMsoNormal, .ExternalClass div.ecxMsoNormal {margin-bottom:.0001pt;font-size:11.0pt;font-family:'Calibri','sans-serif';} .ExternalClass a:link, .ExternalClass span.ecxMsoHyperlink {color:blue;text-decoration:underline;} .ExternalClass a:visited, .ExternalClass span.ecxMsoHyperlinkFollowed {color:purple;text-decoration:underline;} .ExternalClass span.ecxE-MailFormatvorlage17 {font-family:'Calibri','sans-serif';color:windowtext;} .ExternalClass .ecxMsoChpDefault {;} <at> page Section1 {size:612.0pt 792.0pt;} .ExternalClass div.ecxSection1 {page:Section1;}

Hello,

 

is it allowed to sign the log4net.dll with my own digital signature?

 

Thanks in advance,

Michael

 


View your other email accounts from your Hotmail inbox. Add them now.
Michael Hablich | 12 Oct 2009 13:57

AW: Signing the log4net.dll with a digital signature

One prerequisite for Windows certification (for the software) is having all deployed DLLs digitally signed wheter from the original developer or the deployer.

 

Von: Karim Bourouba [mailto:karym6 <at> hotmail.com]
Gesendet: Montag, 12. Oktober 2009 13:51
An: log4net-user <at> logging.apache.org
Betreff: RE: Signing the log4net.dll with a digital signature

 

I would say yes, it is. But I am not sure as to why you would want to do this?



 

From: m.hablich <at> tricentis.com
To: log4net-user <at> logging.apache.org
Date: Mon, 12 Oct 2009 13:06:34 +0200
Subject: Signing the log4net.dll with a digital signature

Hello,

 

is it allowed to sign the log4net.dll with my own digital signature?

 

Thanks in advance,

Michael

 

 

View your other email accounts from your Hotmail inbox. Add them now.


Gmane