Use log4net in SDK

I provide an SDK using C #. To enable field debugging, I want to enable logging using log4net. How to enable customization without using App.config, since the assembly will be a DLL?

Thanks,

+3
c # dll sdk log4net
source share
4 answers

Consider using XmlConfigurator to configure the offline location of the configuration file for log4net. You can use this technique to provide independent file-based configurations without having to touch the \ web.config application or have hard code. Example:

http://haacked.com/archive/2005/03/07/ConfiguringLog4NetForWebApplications.aspx

Update

Try using the following boot file to configure a stand-alone configuration file. He will build the full path. Try to get out of the way if he is still having trouble finding it.

public static class LogFactory { public const string ConfigFileName = "log4net.config"; public static void Configure() { Type type = typeof(LogFactory); FileInfo assemblyDirectory = AssemblyInfo.GetCodeBaseDirectory(type); string path = Path.Combine(assemblyDirectory.FullName, ConfigFileName); FileInfo configFile = new FileInfo(path); XmlConfigurator.ConfigureAndWatch(configFile); log4net.ILog log = LogManager.GetLogger(type); log.ToString(); } } 

Call:

 LogFactory.Configure(); 
+6
source share

you can put the configuration in code, although not recommended.

it is better to send a dll with an external file or add code - if the file exists, use it, if not, use a hard-coded configuration.

+1
source share

Why not make an aggregated SDK logging platform by providing an abstraction of your registrar? Caliburn.Micro does this, and this article describes how it works and how the client can configure the appropriate registrar that they want to use - http://buksbaum.us/2010/08/08/how-to-do-logging- with-caliburn-micro /

0
source share

You may also consider using the Common.Logging paragraph for .Net.

http://netcommon.sourceforge.net/

Common.Logging supports log4net, NLog, and the corporate library out of the box. It's easy to write your own adapter for use with Common.Logging if you need to.

Thus, your SDK becomes an agnostic registration platform. The user will still need an entry in app.config or web.config to indicate which platform to use, but the configuration of a specific platform can still be stored in a separate file.

0
source share

All Articles