public override BootstrappingResult Execute()
{
var assemblyPath = this._request.ComponentPath;
if (!File.Exists(Path.Combine(assemblyPath, "log4net.dll")))
{
// no log4net requires no modifications.
return BootstrappingResult.Success();
}
var potentialAssemblies =
Directory.EnumerateFiles(assemblyPath, "*.dll")
.Where(p => AssemblyExtensions.HasDependencyOn(p, "log4net"))
.ToArray();
if (potentialAssemblies.Any())
{
var assemblyStream =
Assembly.GetExecutingAssembly()
.GetManifestResourceStream("Apprenda.Log4NetConnectorPolicy.Resources.log4net.Apprenda.dll");
if (assemblyStream != null)
{
var appenderPath = Path.Combine(assemblyPath, "log4net.Apprenda.dll");
if (!File.Exists(appenderPath))
{
using (var appenderStream = new FileStream(appenderPath, FileMode.Create))
{
assemblyStream.CopyTo(appenderStream );
}
}
}
else
{
return BootstrappingResult.Failure(new[] { "Failed to copy logging assembly to the output path." });
}
}
var configFilePaths = potentialAssemblies.Select(
filePath =>
{
var configFileName = GetXmlConfiguratorProperty(filePath, "ConfigFile");
if (configFileName != null)
{
return Path.Combine(assemblyPath, configFileName);
}
var configExtension = GetXmlConfiguratorProperty(filePath, "ConfigFileExtension") ?? "config";
return filePath + (configExtension.StartsWith(".") ? "." : string.Empty) + configExtension;
});
var messages =
configFilePaths.SelectMany(
configFilePath => new Log4NetConfigurationUpdateService(configFilePath).Update());
return BootstrappingResultExtension.SuccessIfNoMessages(messages);
}