Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

log4net doesn't create a log file for a referenced project file

I am building an application that calls upon a compiled executable. Said executable's source code project file is referenced by the solution file for the parent application. The child executable is a stand alone command line application. The parent is a effectively a GUI wrapper to the console application. When I compile the console application, I have access to all of log4net's functionality that has been built into the application. However, when I compile the parent project that references the console application's source code files, everything runs correctly but no logs are generated. What would cause this error to occur, and how can this occurrence be fixed? log4net's internal debugging mechanism doesn't throw any messages.

like image 915
XBigTK13X Avatar asked Jan 22 '23 18:01

XBigTK13X


2 Answers

For log4net to start logging within the referenced assembly you will have to:

  • Call the Configure() function of log4net by either calling log4net.Config.XmlConfigurator.Configure() when your application starts, or by adding [assembly: log4net.Config.XmlConfigurator(Watch=true)] to the AssemblyInfo.cs file of your wrapper application.
  • Create an log4net configuration section in the app.config for your GUI wrapper if you haven't already done so. Add an app.config file to your project, and copy your log4net configuration information from the referenced library into it.
  • Ensure that the account running the application has access to write and create files within the log directory (assuming your using file-based logging).

For more info about setting up your config see: http://logging.apache.org/log4net/release/manual/configuration.html

like image 78
Joe Avatar answered Jan 24 '23 09:01

Joe


I know it's too late but anyway just for reference. Set log4net.Internal.Debug = true in your application and you might see the problem on the console. (do this programmatically since your application might not be able to find it's config file, which was what happened in my case)

On the Process p, after you exec the process using p.start() try to write the stdout to console with this; Console.write(p.StandardOutput.ReadToEnd());

You should be able to see the problem. (why log4net isn't getting configured or why it isn't logging) In my case it was looking for the app.config file in the parent process's working directory. (my app and it's config are present elsewhere on the file system)

like image 34
Kaysee Avatar answered Jan 24 '23 08:01

Kaysee