I am trying to log some information inside a CRM 2011 plugin. I am not sure how to configure log4net. Where should I put log4net config file and how to reference from the plugin? Thanks!
Assuming you are registering your plugins to the database, you have a couple options:
Embed the log4net config file in the plugin assembly and configure log4net from a stream (shown below in a plugin base class that other plugins who wish to log could inherit from)
namespace TestPlugins
{
public abstract class BaseLoggingPlugin
{
protected static readonly ILog _log = LogManager.GetLogger(typeof(BaseLoggingPlugin));
static BaseLoggingPlugin()
{
using(var config = Assembly.GetExecutingAssembly().GetManifestResourceStream("TestPlugins.log4net.config"))
{
XmlConfigurator.Configure(config);
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With