예제 #1
0
 private void ParseFormatters()
 {
     if (!(_root["formatters"] is JObject formatterNodes))
     {
         return;
     }
     foreach (var formatterNode in formatterNodes)
     {
         var definition = new FormatterDefinition();
         definition = ParseDefinition(definition, formatterNode.Value);
         _configuration.Formatters.Add(definition.Id, definition);
     }
 }
예제 #2
0
        private LogDefinition ParseLogDefinition(JObject logNode)
        {
            var definition = new LogDefinition();

            definition = ParseDefinition(definition, logNode, "", "formatter", "listeners", "sinks");

            var formatterNode = logNode["formatter"];

            if (formatterNode != null)
            {
                if (formatterNode.Type == JTokenType.String)
                {
                    definition.FormatterName = formatterNode.Value <string>();
                }
                else
                {
                    var    formatterDefinition = new FormatterDefinition();
                    string name = definition.Id + "_formatter";
                    formatterDefinition = ParseDefinition(formatterDefinition, formatterNode, name);

                    _configuration.Formatters.Add(name, formatterDefinition);
                    definition.FormatterName = name;
                }
            }

            var listenerNodes = logNode["listeners"];

            if (listenerNodes != null)
            {
                foreach (var listenerNode in listenerNodes)
                {
                    if (listenerNode.Type == JTokenType.String)
                    {
                        definition.ListenerNames.Add(formatterNode.Value <string>());
                    }
                    else
                    {
                        var name = definition.Id + "_listener" + DateTime.Now.Ticks;
                        var listenerDefinition = new ListenerDefinition();
                        listenerDefinition = ParseDefinition(listenerDefinition, listenerNode, name);

                        _configuration.Listeners.Add(name, listenerDefinition);
                        definition.ListenerNames.Add(name);
                    }
                }
            }

            var sinkNodes = logNode["sinks"];

            if (sinkNodes != null)
            {
                foreach (var sinkNode in sinkNodes)
                {
                    if (sinkNode.Type == JTokenType.String)
                    {
                    }
                    else
                    {
                        var name           = definition.Id + "_sink" + DateTime.Now.Ticks;
                        var sinkDefinition = new SinkDefinition();
                        sinkDefinition = ParseDefinition(sinkDefinition, sinkNode, name);

                        _configuration.Sinks.Add(name, sinkDefinition);
                        definition.SinkNames.Add(name);
                    }
                }
            }

            return(definition);
        }