NServiceBus.RegistryReader.Read C# (CSharp) Method

Read() public static method

public static Read ( string name, string defaultValue = null ) : string
name string
defaultValue string
return string
        public static string Read(string name, string defaultValue = null)
        {
            try
            {
                return ReadRegistryKeyValue(name, defaultValue);
            }
            catch (Exception ex)
            {
                Logger.Warn($@"Could not read the registry to retrieve the {name}, from 'HKEY_LOCAL_MACHINE\SOFTWARE\ParticularSoftware\ServiceBus'.", ex);
            }

            return defaultValue;
        }

Usage Example

        /// <summary>
        /// Forward messages that have repeatedly failed to another endpoint.
        /// </summary>
        /// <param name="config"></param>
        /// <returns></returns>
        public static Configure MessageForwardingInCaseOfFault(this Configure config)
        {
            if (ErrorQueue != null)
            {
                return(config);
            }
            if (SettingsHolder.Get <bool>("Endpoint.SendOnly"))
            {
                return(config);
            }

            ErrorQueue = Address.Undefined;

            var section = Configure.GetConfigSection <MessageForwardingInCaseOfFaultConfig>();

            if (section != null)
            {
                if (string.IsNullOrWhiteSpace(section.ErrorQueue))
                {
                    throw new ConfigurationErrorsException(
                              "'MessageForwardingInCaseOfFaultConfig' configuration section is found but 'ErrorQueue' value is missing." +
                              "\n The following is an example for adding such a value to your app config: " +
                              "\n <MessageForwardingInCaseOfFaultConfig ErrorQueue=\"error\"/> \n");
                }

                Logger.Debug("Error queue retrieved from <MessageForwardingInCaseOfFaultConfig> element in config file.");

                ErrorQueue = Address.Parse(section.ErrorQueue);

                config.Configurer.ConfigureComponent <FaultManager>(DependencyLifecycle.InstancePerCall)
                .ConfigureProperty(fm => fm.ErrorQueue, ErrorQueue);

                return(config);
            }


            var errorQueue = RegistryReader <string> .Read("ErrorQueue");

            if (!string.IsNullOrWhiteSpace(errorQueue))
            {
                Logger.Debug("Error queue retrieved from registry settings.");
                ErrorQueue = Address.Parse(errorQueue);

                config.Configurer.ConfigureComponent <FaultManager>(DependencyLifecycle.InstancePerCall)
                .ConfigureProperty(fm => fm.ErrorQueue, ErrorQueue);
            }

            if (ErrorQueue == Address.Undefined)
            {
                throw new ConfigurationErrorsException("Faults forwarding requires an error queue to be specified. Please add a 'MessageForwardingInCaseOfFaultConfig' section to your app.config" +
                                                       "\n or configure a global one using the powershell command: Set-NServiceBusLocalMachineSettings -ErrorQueue {address of error queue}");
            }

            return(config);
        }
All Usage Examples Of NServiceBus.RegistryReader::Read