How to configure log4net to work inside the CRM 2011 plugin?

I am trying to write some information inside the CRM 2011 plugin. I am not sure how to configure log4net. Where should I put the log4net configuration file and how to reference the plugin? Thanks!

+4
source share
2 answers

Assuming you are registering your plugins in a database, you have several options:

  • Configure log4net programmatically. This can be done using the log4net API and can be controlled by the configuration object in crm.
  • Insert the log4net configuration file into the plug-in assembly and configure log4net from the stream (shown below in the base class of the plug-in, which other plug-ins that want to write the log can 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); } } } } 
+8
source

I want to add a warning to what ends with the correct answer: if you register your assembly of plugins as a sandbox assembly (for CRM-online, sandbox mode is required), you will not have access to the file system. In this case, your only option is Tracing . Good luck

0
source

Source: https://habr.com/ru/post/1399196/


All Articles