July 2009 Entries

  • 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" />...