0

I am loading a .NET application using the ICLRRuntimeHost::ExecuteInDefaultAppDomain method which starts the application up fine. However, the application is using Log4Net with which it should output an info message after starting up, but it never does. It works fine when opening it up normally though, so it must be something with the CLR Hosting environment that makes it unable to function properly, I just don't know what exactly.

Here is the code that does the logging:

using System;
using System.Windows.Forms;

using log4net;

namespace TestApplication
{
    public partial class MainForm : Form
    {
        private static readonly ILog log = LogManager.GetLogger
        (MethodBase.GetCurrentMethod().DeclaringType);

        public MainForm()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            log.Info("Application has started");
        }
    }
}
J. Zeptra
  • 9
  • 2
  • Can you please the code that should do the logging? – Tobias Theel Nov 09 '17 at 14:26
  • Sure, here's a minimal example: ``using System; using System.Windows.Forms; using log4net; namespace TestApplication { public partial class MainForm : Form { private static readonly ILog log = LogManager.GetLogger (MethodBase.GetCurrentMethod().DeclaringType); public MainForm() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { log.Info("Application has started"); } } }`` – J. Zeptra Nov 09 '17 at 14:29
  • 1
    I added the code to the OP so it's easier to read. – J. Zeptra Nov 09 '17 at 14:35
  • Have you tried to specify the logpath? https://stackoverflow.com/a/17740806/4992212 – Tobias Theel Nov 09 '17 at 14:36
  • Just tried doing that, but that also only works when running the application manually. On a side note though, when calling `Config.XmlConfigurator.Configure()`, it gives me the following error, only when using the CLR hosting API: _Failed to find configuration section 'log4net' in the application's .config file._ Before testing this, I only had this line of code in the Program.cs file: `[assembly: XmlConfigurator(Watch = false)]`, which works in the original application, but also doesn't yield any errors in the hosted application. – J. Zeptra Nov 09 '17 at 15:08
  • Can you show the code that calls `ExecuteInDefaultAppDomain` ? – Dieter Meemken Jan 25 '18 at 09:53

0 Answers0