Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to configure log4net to work inside a CRM 2011 plugin?

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!

like image 758
user1201405 Avatar asked Feb 21 '23 07:02

user1201405


1 Answers

Assuming you are registering your plugins to the database, you have a couple options:

  1. Configure log4net programmatically. This can be done via the log4net API and could be driven by a configuration entity in crm.
  2. 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);
                }
            }
        }
    }
    
like image 166
Matt Dearing Avatar answered Mar 08 '23 03:03

Matt Dearing