public UdpGelfClient(GelfLoggerOptions options) { _options = options; _maxMessageBodySize = options.UdpMaxChunkSize - MessageHeaderSize; _udpClient = new UdpClient(_options.Host, _options.Port); _random = new Random(); }
private static IGelfClient CreateGelfClient(GelfLoggerOptions options) { return(options.Protocol switch { GelfProtocol.Udp => (IGelfClient) new UdpGelfClient(options), GelfProtocol.Http => new HttpGelfClient(options), GelfProtocol.Https => new HttpGelfClient(options), _ => throw new ArgumentException("Unknown protocol.", nameof(options)) });
public HttpGelfClient(GelfLoggerOptions options) { var uriBuilder = new UriBuilder { Scheme = options.Protocol.ToString().ToLower(), Host = options.Host, Port = options.Port }; _httpClient = new HttpClient { BaseAddress = uriBuilder.Uri, Timeout = options.HttpTimeout }; }
private static IGelfClient CreateGelfClient(GelfLoggerOptions options) { switch (options.Protocol) { case GelfProtocol.Udp: return(new UdpGelfClient(options)); case GelfProtocol.Http: case GelfProtocol.Https: return(new HttpGelfClient(options)); default: throw new ArgumentException("Unknown protocol.", nameof(options)); } }
public GelfLoggerProvider(GelfLoggerOptions options) { if (string.IsNullOrEmpty(options.Host)) { throw new ArgumentException("GELF host is required.", nameof(options)); } if (string.IsNullOrEmpty(options.LogSource)) { throw new ArgumentException("GELF log source is required.", nameof(options)); } _options = options; _gelfClient = CreateGelfClient(_options); _messageProcessor = new GelfMessageProcessor(_gelfClient); _messageProcessor.Start(); }
public HttpGelfClient(GelfLoggerOptions options) { var uriBuilder = new UriBuilder { Scheme = options.Protocol.ToString().ToLower(), Host = options.Host, Port = options.Port }; _httpClient = new HttpClient { BaseAddress = uriBuilder.Uri, Timeout = options.HttpTimeout }; foreach (var header in options.HttpHeaders) { _httpClient.DefaultRequestHeaders.Add(header.Key, header.Value); } }
public UdpGelfClient(GelfLoggerOptions options) { _options = options; _udpClient = new UdpClient(); _random = new Random(); }
public GelfLogger(string name, GelfMessageProcessor messageProcessor, GelfLoggerOptions options) { _name = name; _messageProcessor = messageProcessor; _options = options; }
/// <summary> /// Adds a <see cref="GelfLoggerProvider"/> to the logger factory with the supplied /// <see cref="GelfLoggerOptions"/>. /// </summary> /// <param name="loggerFactory"></param> /// <param name="options"></param> /// <returns></returns> public static ILoggerFactory AddGelf(this ILoggerFactory loggerFactory, GelfLoggerOptions options) { loggerFactory.AddProvider(new GelfLoggerProvider(options)); return(loggerFactory); }
/// <summary> /// Adds a <see cref="GelfLoggerProvider" /> to the logger factory with the supplied /// <see cref="GelfLoggerOptions" />. /// </summary> /// <param name="loggerFactory"></param> /// <param name="options"></param> /// <returns></returns> public static ILoggerFactory AddGelf(this ILoggerFactory loggerFactory, GelfLoggerOptions options) { return(loggerFactory.AddGelf(new OptionsMonitorStub <GelfLoggerOptions>(options))); }