コード例 #1
0
        public virtual void Log(string message, IDictionary <string, string> properties)
        {
            var level    = Level.Debug;
            var facility = Facility.Daemon;

            if (properties is null)
            {
                properties = new Dictionary <string, string>();
            }

            if (properties.ContainsKey(nameof(Category)) && Enum.TryParse(properties[nameof(Category)], out Category category))
            {
                level = category.ToLevel();
            }

            if (properties.ContainsKey(nameof(Facility)) && Enum.TryParse(properties[nameof(Facility)], out Facility fac))
            {
                facility = fac;
            }

            var props = properties?.Where(x => x.Key != nameof(Category) && x.Key != nameof(Facility))
                        .Select(prop => $"\n    {prop.Key} - {prop.Value}") ?? Array.Empty <string>();

            var syslog = new SyslogMessage(facility, level, $"{message}\nProperties{string.Join("", props)}")
            {
                AppName = AppNameOrTag
            };

            SendMessage(syslog);
        }
コード例 #2
0
        public virtual void Log(string message, IDictionary <string, string> properties)
        {
            if (properties is null)
            {
                properties = new Dictionary <string, string>();
            }

            if (properties.ContainsKey(nameof(Level)) && Enum.TryParse(properties[nameof(Level)], out Level level))
            {
                properties.Remove(nameof(Level));
            }
            else if (properties.ContainsKey("Category") && Enum.TryParse(properties["Category"], out level))
            {
                properties.Remove("Category");
            }
            else
            {
                level = Level.Debug;
            }

            if (properties.ContainsKey(nameof(Facility)) && Enum.TryParse(properties[nameof(Facility)], out Facility facility))
            {
                properties.Remove(nameof(Facility));
            }
            else
            {
                facility = Facility.Daemon;
            }

            var props = properties?.Select(prop => $"\n    {prop.Key} - {prop.Value}") ?? Array.Empty <string>();

            var syslog = new SyslogMessage(facility, level, $"{message}\nProperties{string.Join("", props)}")
            {
                AppName = AppNameOrTag
            };

            SendMessage(syslog);
        }
コード例 #3
0
 protected bool SendMessage(SyslogMessage message) =>
 SendMessage(message, HostNameOrIp, Port);
コード例 #4
0
 protected IEnumerable <string> Chunkify(SyslogMessage baseMessage, string text) =>
 Chunkify(baseMessage.ToString(), text);