コード例 #1
0
        public virtual Dictionary <string, object> DoInvoke(IDynamicLoggerProvider provider, LoggersChangeRequest request)
        {
            Dictionary <string, object> result = new Dictionary <string, object>();

            if (request != null)
            {
                SetLogLevel(provider, request.Name, request.Level);
            }
            else
            {
                AddLevels(result);
                var configuration = GetLoggerConfigurations(provider);
                Dictionary <string, LoggerLevels> loggers = new Dictionary <string, LoggerLevels>();
                foreach (var c in configuration.OrderBy(entry => entry.Name))
                {
                    _logger.LogTrace("Adding " + c.ToString());
                    LoggerLevels lv = new LoggerLevels(c.ConfiguredLevel, c.EffectiveLevel);
                    loggers.Add(c.Name, lv);
                }

                result.Add("loggers", loggers);
            }

            return(result);
        }
コード例 #2
0
        private bool ChangeLoggerLevel(HttpRequest request, string path)
        {
            var epPath = new PathString(path);

            if (request.Path.StartsWithSegments(epPath, out var remaining) && remaining.HasValue)
            {
                var loggerName = remaining.Value.TrimStart('/');

                var change = ((LoggersEndpoint)_endpoint).DeserializeRequest(request.Body);

                change.TryGetValue("configuredLevel", out var level);

                _logger?.LogDebug("Change Request: {0}, {1}", loggerName, level ?? "RESET");

                if (!string.IsNullOrEmpty(loggerName))
                {
                    if (!string.IsNullOrEmpty(level) && LoggerLevels.MapLogLevel(level) == null)
                    {
                        _logger?.LogDebug("Invalid LogLevel specified: {0}", level);
                    }
                    else
                    {
                        var changeReq = new LoggersChangeRequest(loggerName, level);
                        HandleRequest(changeReq);
                        return(true);
                    }
                }
            }

            return(false);
        }
コード例 #3
0
        public virtual void SetLogLevel(IDynamicLoggerProvider provider, string name, string level)
        {
            if (provider == null)
            {
                _logger?.LogInformation("Unable to access Cloud Foundry Logging provider, log level not changed");
                return;
            }

            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException(nameof(name));
            }

            provider.SetLogLevel(name, LoggerLevels.MapLogLevel(level));
        }