Enterprise Library not logging in setup project

48 views Asked by At

I need your opinion on this: Is it possible to use enterprise library logging dll in the setup project?

Here's what I did: I created a setup project which will call a windows form to install the database. When I installed the project, it did call the windows form. However, when I click on the "Install" button, it seems that there's a problem and I don't know where it is. Then another popup message is displayed which said that it cannot locate the logging configuration.

But the config file for the windows form is there which includes the configuration for the logging dll. I don't have any idea where to look into.

Please help me with this?

Below is the error message: enter image description here

UPDATE I observed that when I run the exe file as is, the enterprise library logging config works. But with the setup project, it does not look for it. Any help on this?

Below is the code for this:

[RunInstaller(true)]
public partial class IPWInstaller : Installer
{
    public IPWInstaller()
    {
        InitializeComponent();
    }

    public override void Install(IDictionary stateSaver)
    {
        base.Install(stateSaver);
        string targetPath = Context.Parameters["TargetDir"];
        InstallDatabase db = new InstallDatabase(targetPath);

        DialogResult dbResult = db.ShowDialog();

        if (dbResult != DialogResult.OK)
        {
            throw new InstallException("Database is not installed.");
        }

        ConfigureFiles config = new ConfigureFiles(targetPath);
        DialogResult configResult = config.ShowDialog();

        if (configResult != DialogResult.OK)
        {
            throw new InstallException("Config files are not saved correctly.");
        }
    }
}

LATEST UPDATE:

I tried to set the value of a certain configuration to my messagebox. This is the result of it when I run the install project. enter image description here

Is there a way to call my app.config in the setup project

1

There are 1 answers

3
PhilDW On BEST ANSWER

There are at least a couple of things that can go wrong.

The app is not running as it would if you ran it as an interactive user. It is being called from an msiexec.exe process that knows nothing about your intended environment, such as working directory. None of the automatic things that happen because you run from an explorer shell will happen. Any paths you use need to be full and explicit. I think you may need to explicitly load your settings file.

Something else that can happen in a per machine install is that custom actions run with the system account so any code which assumes you have access to databases, user profile items like folders can fail.

Another problem is that Windows Forms often don't work well when called from a VS custom action. It's not something that works very well because that environment is not the STA threading model that is required for window messages etc.

In general it's better to run these config programs after the install the first time the app starts because then you are in a normal environment, debugging and testing is straightforward, and if the db gets lost the user could run the program again to recreate it instead of uninstalling and reinstalling the setup.