List Info

Thread: log4net configuration withtou Xml file




log4net configuration withtou Xml file
country flaguser name
Germany
2008-05-05 02:31:54
Hello Everyone,
 
    I need to be able to configure log4net without the XmlConfigurator, that is directly from my code.
    I am aware of the BasicConfigurator but one appender is not enough for me.
 
    I would like to be able to create some new appenders, remove (or disable) them and change their
    log threshold at runtime. I am working under Compact Framework 2.0.
 
    I already took a look at this logging.apache.org/msg02895.html">http://www.mail-archive.com/log4net-userlogging.apache.org/msg02895.html ) mail that gave me many informations,
    but did not yet found how to create an appender and register it not for one logger but for all (and all the ones that will be created after I registered my appender).
 
    In fact how can I achieve a configuration like the following file but programmatically:
 
 &nbsp;  <configuration>
 <log4net>  ;
 &nbsp;<appender name="TextLogFileAppender" type="log4net.Appender.FileAppender" >
&nbsp; &nbsp;<file value="log.xml" />
&nbsp; &nbsp;<appendToFile value="true" />
&nbsp; &nbsp;<layout type="log4net.Layout.XmlLayoutSchemaLog4j" />
&nbsp; &nbsp;<param name="Threshold" value="ERROR" />
&nbsp; &lt;/appender>
 
&nbsp; &lt;appender name="ConsoleErrorAppender" type="log4net.Appender.ConsoleAppender"&gt;
 &nbsp; &lt;layout type="log4net.Layout.PatternLayout">
&nbsp;   ;<conversionPattern value="%date [%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; - %message%newline" />
&nbsp; &nbsp;</layout>
&nbsp;  <param name="Threshold" value="FATAL" />
&nbsp; &lt;/appender>
 
&nbsp; &lt;appender name="UdpAppender" type="log4net.Appender.UdpAppender">
&nbsp;  <localPort value="8080" />
&nbsp; &nbsp;<remoteAddress value="192.168.1.1" />
&nbsp; &nbsp;<remotePort value="8080" />
&nbsp; &nbsp;<layout type="log4net.Layout.XmlLayoutSchemaLog4j">
 ; &nbsp; <;locationInfo value="true" />
&nbsp; &nbsp;</layout>
&nbsp;  <param name="Threshold" value="DEBUG" />
&nbsp; &lt;/appender>
 
 &nbsp;<!-- Setup the root category, add the appenders and set the default level -->&nbsp; 
  ;<root&gt;
 &nbsp; &lt;appender-ref ref="TextLogFileAppender" />
&nbsp; &nbsp;<appender-ref ref="ConsoleErrorAppender" />
&nbsp; &nbsp;<appender-ref ref="UdpAppender" />
&nbsp; &lt;/root>
&nbsp;</log4net>
&lt;/configuration>
 
 
 &nbsp;  Best regards and many thanks in advance for any help,
 
 &nbsp;  Bruno
 
Bruker BioSpin GmbH

Bruno Knittel
Automation Development

Bruker BioSpin GmbH
Silberstreifen
76287 Rheinstetten

Germany
 Phone: +49 721 5161-90064
 Fax:     +49 721 5161-494


Bruker BioSpin GmbH: Sitz der Gesellschaft/Registered Office: Rheinstetten, HRB 102368 Amtsgericht Mannheim
Geschäftsführer/Managing Directors: Dr. Bernd Gewiese, Dr. Dieter Schmalbein, Dr. Gerhard Roth

Diese E-Mail und alle Anlagen können Betriebs- oder Geschäftsgeheimnisse, oder sonstige vertrauliche Informationen enthalten. Sollten Sie diese E-Mail irrtümlich erhalten haben, ist Ihnen eine Kenntnisnahme des Inhalts, eine Vervielfältigung oder Weitergabe der E-Mail und aller Anlagen ausdrücklich untersagt. Bitte benachrichtigen Sie den Absender und löschen/vernichten Sie die empfangene E-Mail und alle Anlagen.
Vielen Dank.


This message and any attachments may contain trade secrets or privileged, undisclosed or otherwise confidential information. If you have received this e-mail in error, you are hereby notified that any review, copying or distribution of it and its attachments is strictly prohibited. Please inform the sender immediately and delete/destroy the original message and any copies.
Thank you.

&nbsp;
RE: log4net configuration withtou Xml file
country flaguser name
Czech Republic
2008-05-06 01:00:08
Hello Bruno,
configuring log4net directly from the code is my dream too, but documentation did not give any example how to do this.
It is simple if you need to use the only appender - use BasicConfigurator:
 
 &nbsp; log4net.Appender.FileAppender fa = new log4net.Appender.FileAppender();
 &nbsp; fa.AppendToFile = false;
&nbsp;  fa.File = "ipagent.log";
&nbsp; &nbsp;fa.Layout = new log4net.Layout.PatternLayout("%date{dd-MM-yyyy HH:mm:ss,fff} %5level [%2thread] %message (%logger{1}:%line)%n");
 &nbsp; fa.Threshold = log4net.Core.Level.Debug;
&nbsp; &nbsp;fa.ActivateOptions();
 &nbsp; log4net.Config.BasicConfigurator.Configure(fa);
 
I have this tested and it works well. But when configuration is more complex, I didn't found a way how to make logging to work. Look&nbsp;at this message logging.apache.org/msg03890.html">http://www.mail-archive.com/log4net-userlogging.apache.org/msg03890.html, there you find a piece of my (nonworking) code.
If you'll be able to find what is missing there, let me know
 
Radovan Raszka

From: Knittel Bruno [mailto:Bruno.Knittelbruker-biospin.de]
Sent: Monday, May 05, 2008 9:32 AM
To: log4net-userlogging.apache.org
Subject: log4net configuration withtou Xml file

Hello Everyone,
 
 &nbsp;  I need to be able to configure log4net without the XmlConfigurator, that is directly from my code.
 &nbsp;  I am aware of the BasicConfigurator but one appender is not enough for me.
 
 &nbsp;  I would like to be able to create some new appenders, remove (or disable) them and change their
 &nbsp;  log threshold at runtime. I am working under Compact Framework 2.0.
 
 &nbsp;  I already took a look at this logging.apache.org/msg02895.html">http://www.mail-archive.com/log4net-userlogging.apache.org/msg02895.html ) mail that gave me many informations,
 &nbsp;  but did not yet found how to create an appender and register it not for one logger but for all (and all the ones that will be created after I registered my appender).
 
 &nbsp;  In fact how can I achieve a configuration like the following file but programmatically:
 
 &nbsp;  <configuration>
 <log4net>  ;
 &nbsp;<appender name="TextLogFileAppender" type="log4net.Appender.FileAppender" >
 ; &nbsp;<file value="log.xml" />
&nbsp; &nbsp;<appendToFile value="true" />
&nbsp; &nbsp;<layout type="log4net.Layout.XmlLayoutSchemaLog4j" />
&nbsp; &nbsp;<param name="Threshold" value="ERROR" />
&nbsp; <;/appender&gt;
 &nbsp;
 ; <appender name="ConsoleErrorAppender" type="log4net.Appender.ConsoleAppender">
 &nbsp; <;layout type="log4net.Layout.PatternLayout">
&nbsp; &nbsp; &lt;conversionPattern value="%date [%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; - %message%newline" />
&nbsp; &nbsp;</layout>
&nbsp; &nbsp;<param name="Threshold" value="FATAL" />
&nbsp; <;/appender&gt;
 &nbsp;
 ; <appender name="UdpAppender" type="log4net.Appender.UdpAppender">
&nbsp; &nbsp;<localPort value="8080" />
&nbsp; &nbsp;<remoteAddress value="192.168.1.1" />
&nbsp; &nbsp;<remotePort value="8080" />
&nbsp; &nbsp;<layout type="log4net.Layout.XmlLayoutSchemaLog4j"&gt;
 &nbsp;  <locationInfo value="true" />
&nbsp; &nbsp;</layout>
&nbsp; &nbsp;<param name="Threshold" value="DEBUG" />
&nbsp; <;/appender&gt;
 
 &nbsp;<!-- Setup the root category, add the appenders and set the default level -->&nbsp; 
&nbsp; &lt;root>
 &nbsp; <;appender-ref ref="TextLogFileAppender" />
&nbsp; &nbsp;<appender-ref ref="ConsoleErrorAppender" />
&nbsp; &nbsp;<appender-ref ref="UdpAppender" />
&nbsp; <;/root>&nbsp;
 ;</log4net>
</configuration>
 
 
 &nbsp;  Best regards and many thanks in advance for any help,
 
 &nbsp;  Bruno
 
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )