log4net in DLLs

Sometimes the deliverable is a class library and specific logging is included.  The configuration file for logging in this case was supposed to be part of the DLL, and stay in the DLL folder, not the executable folder.  To get this to work, I did the following:

In the main constructor of the DLL:
   System.Reflection.Assembly ea = System.Reflection.Assembly.GetExecutingAssembly();
string file = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(ea.Location), "specific.dll.log4net");
log4net.GlobalContext.Properties["SpecificPath"] = System.IO.Path.GetDirectoryName(ea.Location);
log4net.Config.XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo(file));
log.InfoFormat("Initializing SPECIFIC");

And this is what the specific.dll.log4net file looks like:
<?xml version="1.0" encoding="utf-8" ?>
<log4net>
<appender name="FileAppender" type="log4net.Appender.FileAppender">
   <file type="log4net.Util.PatternString" value="%property{SpecificPath}\log-file.txt" />
<appendToFile value="true" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
  </layout>
  </appender>
  <root>
    <level value="DEBUG" />
    <appender-ref ref="FileAppender" />
  </root>
</log4net>

Note the property.  This trick comes from ByteCyclist  Thanks!
Print | posted on Friday, July 17, 2009 2:37 PM

Feedback

# re: log4net in DLLs

left by Kendra at 10/27/2010 10:41 AM Gravatar
hey i did everything you said. Thanks

# Viagra Utilizzo StevLoriuse

left by EdyEtema at 3/6/2020 9:22 AM Gravatar
Buy Doxycycline Us Free Shipping http://apcialisle.com/# - Cialis Doctissimo Kamagra In Linea buy cialis Augmentin Vs Amoxicillin

# Fedex Doryx Mastercard Accepted Cheapeast Elldymn

left by Stepmut at 3/9/2020 12:00 PM Gravatar
Propecia Discography cialis 5 mg best price usa Viagra Super Active 3 8 Day Shipping cialis prices Vanuatu Pharmacy Online

# Buy Tamoxifen No Prescription StevLoriuse

left by EdyEtema at 3/13/2020 2:01 AM Gravatar
Cialis Sans Ordonnance En Pharmacie http://apcialisle.com/# - Cialis Cialis Kamagra En Ligne cialis cheapest online prices Viagra Fa Perdere L'Udito

# Kamagra Facts Elldymn

left by Stepmut at 3/17/2020 10:30 PM Gravatar
Amoxicillin And Doxycycline Together cheapest cialis Keflex Dose Mg Lb cialis price Buy Tadalafil Online

# Xenical Vente Ligne StevLoriuse

left by EdyEtema at 3/19/2020 3:18 PM Gravatar
Buy Propecia Online 5mg https://apcialisle.com/# - Cialis Cytotec Avec Curetage Cialis Prix De Cialis Au Maroc

# Dapoxetine En Ligne StevLoriuse

left by EdyEtema at 4/29/2020 4:17 AM Gravatar
Comprare Cialis Con Postepay https://abuycialisb.com/# - cialis prices Prix Cialis 5mg Pharmacie France Cialis Cialis Achat Avis
Title  
Name
Email (never displayed)
Url
Comments   
Please add 8 and 6 and type the answer here: