Apprenda.Log4NetConnectorPolicy.UserInterfaceWorkloadInspector.ProbeUiComponentForAssemblies C# (CSharp) Method

ProbeUiComponentForAssemblies() private method

Probe each UI component and attach our appender.
private ProbeUiComponentForAssemblies ( string uiPath ) : BootstrappingResult
uiPath string /// The path to this user interface component. ///
return BootstrappingResult
        private BootstrappingResult ProbeUiComponentForAssemblies(string uiPath)
        {
            var binaryPath = Path.Combine(uiPath, "bin");
            var appenderPath = Path.Combine(binaryPath, "log4net.Apprenda.dll");

            if (!File.Exists(Path.Combine(binaryPath, "log4net.dll")))
            {
                // if log4net is not present in the component, this bootstrapper succeeds by not modifying the workload.
                return BootstrappingResult.Success();
            }

            var localAssembly = Assembly.GetExecutingAssembly();
            using (var assemblyStream = localAssembly.GetManifestResourceStream(EmbeddedAssembly))
            {
                if (assemblyStream != null)
                {
                    if (!File.Exists(appenderPath))
                    {
                        try
                        {
                            using (var appenderStream = new FileStream(appenderPath, FileMode.Create))
                            {
                                assemblyStream.CopyTo(appenderStream);
                            }
                        }
                        catch
                        {
                            {
                                return
                                    BootstrappingResult.Failure(new[] { "Failed to copy logging assembly to the output path." });
                            }
                        }
                    }
                }
            }

            var potentialAssemblies = Directory.EnumerateFiles(binaryPath, "*.dll").Except(new[] { appenderPath }).ToList();
            var dependentAssemblies = potentialAssemblies.Where(p => AssemblyExtensions.HasDependencyOn(p, "log4net"));

            var configFilePaths = dependentAssemblies.Select(
                filePath =>
                {
                    var configFileName = GetXmlConfiguratorProperty(filePath, "ConfigFile");
                    if (configFileName != null)
                    {
                        return Path.Combine(uiPath, configFileName);
                    }

                    var configExtension = GetXmlConfiguratorProperty(filePath, "ConfigFileExtension") ?? "config";
                    return filePath + (configExtension.StartsWith(".") ? string.Empty : ".") + configExtension;
                });

            var messages =
                configFilePaths.SelectMany(
                    configFilePath => new Log4NetConfigurationUpdateService(configFilePath).Update());

            var webConfigUpdateMessages = new Log4NetAppConfigUpdateService(Path.Combine(uiPath, "Web.config")).Update();

            return BootstrappingResultExtension.SuccessIfNoMessages(messages.Union(webConfigUpdateMessages));
        }