I wrote a simple CustomAction for my web setup project, but it seems that the code in my CustomAction is never executed.
My custom action looks like this:
Code Snippet
[RunInstaller(true)]
class EventLogCategorySetupAction : Installer
{
public override void Commit(System.Collections.IDictionary savedState)
{
base.Commit(savedState);
string logName = Context.Parameters["logName"];
string categoriesNames = Context.Parameters["categoriesNames"];
if (string.IsNullOrEmpty(logName))
throw new InstallException("Log name must be specified.");
if (string.IsNullOrEmpty(categoriesNames))
throw new InstallException("At least one category name must be specified.");
this.SetEventLogCategories(logName, categoriesNames);
}
public override void Install(System.Collections.IDictionary stateSaver)
{
base.Install(stateSaver);
}
private void SetEventLogCategories(string logName, string categoriesNames)
{
logName = logName.Trim();
string[] categories = categoriesNames.Split(',');
foreach (string category in categories)
{
if (!string.IsNullOrEmpty(category))
{
if (!EventLog.SourceExists(category, Environment.MachineName))
{
EventSourceCreationData escd = new EventSourceCreationData(category, logName);
escd.MachineName = Environment.MachineName;
EventLog.CreateEventSource(escd);
}
}
}
}
Installation completes "successfully" and web site is installed on my IIS, but my problem is that EventLog categories aren't created. It seems that my
SetEventLogCategories method is never called.
There is also one more problem. If I don't write anything in a textboxes of my custom action,
InstallException sholud be thrown because logName and categoriesNames will then be empty. But this isn't a case. No exception is thrown.
My conclusion is that the code of my Installer CustomAction isn't executed. Does anybody have any idea what is happening?
Thanks in advance.