I'm having trouble seeing how I can use logging in my setup / install project.
I've got Log4net working on installed applications, but I can't seem to log the install / uninstall process.
My main problem is with the logging config file.
I suppose it's a bit of a chicken/egg scenario - theres no way for me to grab the just-installed logging file?
I have a method that finds the root directory of my app, using - AppDomain.CurrentDomain.SetupInformation.ApplicationBase
and i normally use this to locate the logging config file.
This directory however, during install, is not where it is installing (obviously) it is somewhere within the windows filesystem.
Does anybody have any ideas to this?
Consider configuring log4net in code and not using a file or storing the configuration as a file resource of your custom action assembly and using XmlConfigurator.Configure(Stream configStream) overload.
Of course if you want to reuse the configuration of the application this is not a clean solution.
Also checkout this question:
log4net pure code configuration with filter in c#
When executing MSI's you are bound to msiexec's logging mechanisms (which is not as friendly as log4net).
Related
I am developing a simple Logger Service (C#2.0) which logs message arrived (via MSMQ) from different clients. Logger Service logging mechanism is using log4net library. I want to have separate file for log4net configuration.
Service is supposed to be installed together with another applications in one common installation package (using WISE).
I want that Logger Service will be provided with that default log4net config file at first installation and write that file on installation directory only if it is missing, otherwise keep existing file.
Please help the newbie.
Have i manage it in installation package or in service.. or in both places?
What is the best way?
Any suggestions are welcome.
XmlCconfigurator.Configure(FileInfo ... )
Allow you to specify a file other than the application configuration file. For the WISE setup: check the docs, I'm sure there is some options to don't overwrite existing files.
I have a Windows Service that I'm creating and I'm wondering what options are available in order for me let developers configure the service.
The service is part of an over all larger open source project and hence the service is going to be installed on lots of different machines.
Normal I would use a web/app.config for this but I'm not sure if this is possible.
Hence I am looking to so how others handle this case.
you do as you expect. You use the app.config, which will be renamed to <exeName>.configwhen the project is built and then <exeName>.config will be read by the service called <exeName>.
Settings are applied in a layered way and may come from other configuration files on the machine, such as machine.config. You can read about how configuration is handled on MSDN
EDIT
In response to comment: A service will only read the config when it starts (for perf reasons). If you want to reload the config file later, you need to handle that yourself I think.
You could read the last modified date/time of the config file to determine if the file has been changed, or setup a file system watcher and then tell the configuration manager to reload that section again next time it is read, by calling ConfigurationManager.RefreshSection("appSettings") and that section will be reloaded from disk when you next access it. See the ConfigurationManager MSDN docs
You can just use a .config file with the same name as the exe that is the service.
If your service runs as MyService.exe, it's config file would be MyService.exe.config.
In Visual Studio, just add an Application Configuration file. This will add an app.config file to the project.
You can then access things like AppSettings and ConnectionStrings using the ConfigurationManager class, just like you do with ASP.Net applications.
I am developing a C# application in Mono and trying to use log4net. The logger works just fine when I load the configuration manually however, I would like something more elegant.
In the log4net documentation it states that a config can be loaded from the assembly by using the following (or similar) line:
[assembly: log4net.Config.XmlConfigurator(ConfigFileExtension="log4net",Watch=true)]
I have ensured the config file gets moved to the build directory and has that extension. I have also made sure the AssemblyInfo.cs is marked "Application Definition" in MonoDevelop. I do not know why this is not working. Does anybody have any ideas?
BTW: I have searched all over the place trying to find an answer. I also tried loading the config from a resource and that did not want to work either.
It is possible, but awkward, to use multiple config files with log4net. See the discussion here: log4net - configure using multiple configuration files
Are you doing logging within your .exe and your .dll?
Can you make do with a single config file?
Bear in mind this section from the documentation: "if you use configuration attributes you must invoke log4net to allow it to read the attributes. A simple call to LogManager.GetLogger will cause the attributes on the calling assembly to be read and processed. Therefore it is imperative to make a logging call as early as possible during the application start-up, and certainly before any external assemblies have been loaded and invoked."
Try and distill the issue down to a simple example.
Ensure your config file is name exename.exe.log4net
Ensure that you place the AssemblyAttribute you have in the quesion, into the AssemblyInfo.cs of your .exe
Ensure that you make a call to LogManager.GetLogger ASAP in your .exe, before invoking any code from your .DLL
I have a class library for which i want to have configuration file.
The purpose of the configuration file is to have the path and other parameters.
Also i wanted to use the Enterprise logging block in Class library.
Here is my scenario:
This is a Class library and will be deployed in GAC
Enterprise logging blocks uses app.Config.
My calling application which consumes the dll is BizTalk 2010.
I don't have permission to modify the BizTalk's application config file
What i am trying to achieve is:
My Dll needs to use a configuration file which has many configuration parameters
Also as i understand, I need app.config for Enterprise Logging
How can i achieve this?
Any ideas?
Cheers,
Karthik
The easiest way is to use the machine config. You also have the option to put your configuration in a separate file and then reference it from the machine config.
You can also set the values in code but that sorta defeats the purpose of using a config file to begin with.
Modify your class library to open and read config file from specific location.
Do you have access to the calling application's code?
If so, maybe you can explicitly load the config file as suggested by Marc_s's solution?
Just an idea.
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.
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
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)