public ILoggingEventPropertiesBuilder WithAdditionalData(IDictionary <string, object> data)
        {
            if (data != null)
            {
                if (data.ContainsKey("AdditionalInfo"))
                {
                    _props.Set("Parameters", data["AdditionalInfo"]);
                }

                foreach (var datum in data)
                {
                    if (_props.Contains(datum.Key))
                    {
                        var duplicatePropsException = new ArgumentException("An element with the same key already exists.");
                        duplicatePropsException.Data.Add("Key", datum.Key);
                        duplicatePropsException.Data.Add("Value1", _props[datum.Key]);
                        duplicatePropsException.Data.Add("Value2", datum.Value);
                        throw duplicatePropsException;
                    }

                    _props.Set(datum.Key, datum.Value);
                }
            }
            return(this);
        }
Example #2
0
        private string Hostname(PropertiesDictionary properties)
        {
            var hostname = String(properties, HostnameKey);

            if (!string.IsNullOrWhiteSpace(hostname))
            {
                return(hostname);
            }
            var log4netHostname = "log4net:HostName";

            if (properties == null || properties.Count == 0 || !properties.Contains(log4netHostname))
            {
                return(null);
            }
            return(properties[log4netHostname].ToString());
        }