/// <inheritdoc />
            public Task <IDiagnosticEventSink> CreateDiagnosticEventSink(IConfiguration configuration)
            {
                var host = configuration?["host"];
                var port = configuration?.GetValue <int>("port") ?? GelfUdpOptions.DefaultPort;
                var enableCompression = configuration?.GetValue <bool>("compress") ?? true;
                var chunkSize         = configuration?.GetValue <int>("chunkSize", GelfUdpOptions.DefaultChunkSize) ?? GelfUdpOptions.DefaultChunkSize;

                if (string.IsNullOrWhiteSpace(host))
                {
                    throw new ConfigurationErrorsException("'host' attribute is required");
                }
                if (port == 0)
                {
                    throw new ConfigurationErrorsException("'port' attribute is required");
                }
                if (port <= 0 || port > 65535)
                {
                    throw new ConfigurationErrorsException("Invalid port");
                }
                if (chunkSize <= 0 || chunkSize > GelfUdpOptions.MaxChunkSize)
                {
                    throw new ConfigurationErrorsException("Invalid chunk size");
                }

                var options = new GelfUdpOptions(host)
                {
                    Port = port,
                    EnableCompression = enableCompression,
                    ChunkSize         = chunkSize
                };

                return(Task.FromResult <IDiagnosticEventSink>(new GelfUdpLoggingSink(options)));
            }
Beispiel #2
0
 /// <summary>
 /// Initializes a new <see cref="GelfUdpLoggingSink"/>
 /// </summary>
 /// <param name="options">Options for configuring the GELF UDP logging sink</param>
 public GelfUdpLoggingSink(GelfUdpOptions options)
 {
     if (options == null)
     {
         throw new ArgumentNullException(nameof(options));
     }
     _host = options.Host;
     _port = options.Port;
     _enableCompression = options.EnableCompression;
     _chunkSize         = options.ChunkSize <= 0
         ? GelfUdpOptions.DefaultChunkSize
         : Math.Min(options.ChunkSize, GelfUdpOptions.MaxChunkSize);
 }