/// <summary>
        /// Graylogs the specified hostname or address.
        /// </summary>
        /// <param name="loggerSinkConfiguration">The logger sink configuration.</param>
        /// <param name="hostnameOrAddress">The hostname or address.</param>
        /// <param name="port">The port.</param>
        /// <param name="transportType">Type of the transport.</param>
        /// <param name="minimumLogEventLevel">The minimum log event level.</param>
        /// <param name="messageIdGeneratorType">Type of the message identifier generator.</param>
        /// <param name="shortMessageMaxLength">Short length of the message maximum.</param>
        /// <param name="stackTraceDepth">The stack trace depth.</param>
        /// <param name="facility">The facility.</param>
        /// <param name="maxMessageSizeInUdp">the maxMessageSizeInUdp</param>
        /// <returns></returns>
        public static LoggerConfiguration Graylog(this LoggerSinkConfiguration loggerSinkConfiguration,
                                                  string hostnameOrAddress,
                                                  int port,
                                                  TransportType transportType,
                                                  LogEventLevel minimumLogEventLevel            = LevelAlias.Minimum,
                                                  MessageIdGeneratortype messageIdGeneratorType = GraylogSinkOptionsBase.DefaultMessageGeneratorType,
                                                  int shortMessageMaxLength = GraylogSinkOptionsBase.DefaultShortMessageMaxLength,
                                                  int stackTraceDepth       = GraylogSinkOptionsBase.DefaultStackTraceDepth,
                                                  string facility           = GraylogSinkOptionsBase.DefaultFacility,
                                                  int maxMessageSizeInUdp   = GraylogSinkOptionsBase.DefaultMaxMessageSizeInUdp)
        {
            // ReSharper disable once UseObjectOrCollectionInitializer
            var options = new GraylogSinkOptions();

            options.HostnameOrAddress = hostnameOrAddress.Expand();
            options.Port                  = port;
            options.TransportType         = transportType;
            options.MinimumLogEventLevel  = minimumLogEventLevel;
            options.MessageGeneratorType  = messageIdGeneratorType;
            options.ShortMessageMaxLength = shortMessageMaxLength;
            options.StackTraceDepth       = stackTraceDepth;
            options.Facility              = facility.Expand();
            options.MaxMessageSizeInUdp   = maxMessageSizeInUdp;

            return(loggerSinkConfiguration.Graylog(options));
        }
Beispiel #2
0
        private ITransport MakeTransport(GraylogSinkOptions options)
        {
            switch (options.TransportType)
            {
            case SerilogTransportType.Udp:

                IDnsInfoProvider dns        = new DnsWrapper();
                IPAddress[]      ipAddreses = Task.Run(() => dns.GetHostAddresses(options.HostnameOrAddress)).Result;
                IPAddress        ipAddress  = ipAddreses.FirstOrDefault(c => c.AddressFamily == AddressFamily.InterNetwork);
                var ipEndpoint = new IPEndPoint(ipAddress, options.Port);

                IDataToChunkConverter chunkConverter = new DataToChunkConverter(new ChunkSettings
                {
                    MessageIdGeneratorType = options.MessageGeneratorType
                }, new MessageIdGeneratorResolver());

                var udpClient    = new UdpTransportClient(ipEndpoint);
                var udpTransport = new UdpTransport(udpClient, chunkConverter);
                return(udpTransport);

            case SerilogTransportType.Http:
                var httpClient    = new HttpTransportClient($"{options.HostnameOrAddress}:{options.Port}/gelf");
                var httpTransport = new HttpTransport(httpClient);
                return(httpTransport);

            default:
                throw new ArgumentOutOfRangeException(nameof(options), options.TransportType, null);
            }
        }
Beispiel #3
0
        public GraylogSink(GraylogSinkOptions options)
        {
            ISinkComponentsBuilder sinkComponentsBuilder = new SinkComponentsBuilder(options);

            _transport = sinkComponentsBuilder.MakeTransport();
            _converter = sinkComponentsBuilder.MakeGelfConverter();
        }
Beispiel #4
0
        public GraylogSink(GraylogSinkOptions options)
        {
            ISinkComponentsBuilder sinkComponentsBuilder = new SinkComponentsBuilder(options);

            _transport = new Lazy <ITransport>(() => sinkComponentsBuilder.MakeTransport());
            _converter = new Lazy <IGelfConverter>(() => sinkComponentsBuilder.MakeGelfConverter());
        }
Beispiel #5
0
        /// <summary>
        /// Graylogs the specified hostname or address.
        /// </summary>
        /// <param name="loggerSinkConfiguration">The logger sink configuration.</param>
        /// <param name="hostnameOrAddress">The hostname or address.</param>
        /// <param name="port">The port.</param>
        /// <param name="transportType">Type of the transport.</param>
        /// <param name="minimumLogEventLevel">The minimum log event level.</param>
        /// <param name="messageIdGeneratorType">Type of the message identifier generator.</param>
        /// <param name="shortMessageMaxLength">Short length of the message maximum.</param>
        /// <param name="stackTraceDepth">The stack trace depth.</param>
        /// <param name="facility">The facility.</param>
        /// <param name="propertyNamingStrategy"></param>
        /// <param name="period"></param>
        /// <param name="batchPostingLimit"></param>
        /// <returns></returns>
        public static LoggerConfiguration Graylog(
            this LoggerSinkConfiguration loggerSinkConfiguration,
            string hostnameOrAddress,
            int port,
            TransportType transportType,
            LogEventLevel minimumLogEventLevel            = LevelAlias.Minimum,
            MessageIdGeneratortype messageIdGeneratorType = GraylogSinkOptions.DefaultMessageGeneratorType,
            int shortMessageMaxLength = GraylogSinkOptions.DefaultShortMessageMaxLength,
            int stackTraceDepth       = GraylogSinkOptions.DefaultStackTraceDepth,
            string facility           = GraylogSinkOptions.DefaultFacility,
            IPropertyNamingStrategy propertyNamingStrategy = null,
            TimeSpan?period       = null,
            int batchPostingLimit = GraylogSinkOptions.DefaultBatchPostingLimit
            )
        {
            var options = new GraylogSinkOptions
            {
                HostnameOrAddress = hostnameOrAddress,
                Port                   = port,
                TransportType          = transportType,
                MinimumLogEventLevel   = minimumLogEventLevel,
                MessageGeneratorType   = messageIdGeneratorType,
                ShortMessageMaxLength  = shortMessageMaxLength,
                StackTraceDepth        = stackTraceDepth,
                Facility               = facility,
                PropertyNamingStrategy = propertyNamingStrategy ?? new NoOpPropertyNamingStrategy(),
                Period                 = period ?? GraylogSinkOptions.DefaultPeriod,
                BatchSizeLimit         = batchPostingLimit
            };

            return(loggerSinkConfiguration.Graylog(options));
        }
Beispiel #6
0
        /// <summary>
        /// Graylogs the specified hostname or address.
        /// </summary>
        /// <param name="loggerSinkConfiguration">The logger sink configuration.</param>
        /// <param name="hostnameOrAddress">The hostname or address.</param>
        /// <param name="port">The port.</param>
        /// <param name="transportType">Type of the transport.</param>
        /// <param name="minimumLogEventLevel">The minimum log event level.</param>
        /// <param name="messageIdGeneratorType">Type of the message identifier generator.</param>
        /// <param name="shortMessageMaxLength">Short length of the message maximum.</param>
        /// <param name="stackTraceDepth">The stack trace depth.</param>
        /// <param name="facility">The facility.</param>
        /// <returns></returns>
        public static LoggerConfiguration Graylog(this LoggerSinkConfiguration loggerSinkConfiguration,
                                                  string hostnameOrAddress,
                                                  int port,
                                                  TransportType transportType,
                                                  LogEventLevel minimumLogEventLevel            = LevelAlias.Minimum,
                                                  MessageIdGeneratortype messageIdGeneratorType = GraylogSinkOptions.DefaultMessageGeneratorType,
                                                  int shortMessageMaxLength = GraylogSinkOptions.DefaultShortMessageMaxLength,
                                                  int stackTraceDepth       = GraylogSinkOptions.DefaultStackTraceDepth,
                                                  string facility           = GraylogSinkOptions.DefaultFacility)
        {
            var options = new GraylogSinkOptions
            {
                HostnameOrAddress = hostnameOrAddress,
                Port                   = port,
                TransportType          = transportType,
                MinimumLogEventLevel   = minimumLogEventLevel,
                MessageGeneratorType   = messageIdGeneratorType,
                ShortMessageMaxLength  = shortMessageMaxLength,
                StackTraceDepth        = stackTraceDepth,
                Facility               = facility,
                PropertyNamingStrategy = new NoOpPropertyNamingStrategy()
            };

            return(loggerSinkConfiguration.Graylog(options));
        }
Beispiel #7
0
        /// <summary>
        /// Graylogs the specified options.
        /// </summary>
        /// <param name="loggerSinkConfiguration">The logger sink configuration.</param>
        /// <param name="options">The options.</param>
        /// <returns></returns>
        public static LoggerConfiguration Graylog(this LoggerSinkConfiguration loggerSinkConfiguration,
                                                  GraylogSinkOptions options)
        {
            var sink = (ILogEventSink) new GraylogSink(options);

            return(loggerSinkConfiguration.Sink(sink, options.MinimumLogEventLevel));
        }
Beispiel #8
0
        public GraylogSink(GraylogSinkOptions options)
        {
            IDnsInfoProvider dns = new DnsWrapper();

            IPAddress[] ipAddreses = Task.Run(() => dns.GetHostAddresses(options.HostnameOrAdress)).Result;

            IPAddress ipAdress = ipAddreses.FirstOrDefault(c => c.AddressFamily == AddressFamily.InterNetwork);

            var ipEndpoint = new IPEndPoint(ipAdress, options.Port);

            IDataToChunkConverter chunkConverter = new DataToChunkConverter(new ChunkSettings
            {
                MessageIdGeneratorType = options.MessageGeneratorType
            }, new MessageIdGeneratorResolver());

            var client = new UdpTransportClient(ipEndpoint);

            _transport = options.Transport ?? new UdpTransport(client, chunkConverter);

            string hostName = Dns.GetHostName();

            IDictionary <BuilderType, IMessageBuilder> builders = new Dictionary <BuilderType, IMessageBuilder>
            {
                [BuilderType.Exception] = new ExceptionMessageBuilder(hostName, options),
                [BuilderType.Message]   = new GelfMessageBuilder(hostName, options)
            };

            _converter = options.GelfConverter ?? new GelfConverter(builders);
        }
        public GraylogSink(GraylogSinkOptions options)
        {
            ISinkComponentsBuilder sinkComponentsBuilder = new SinkComponentsBuilder(options);

            _serializer = JsonSerializer.Create(options.SerializerSettings);
            _transport  = new Lazy <ITransport>(() => sinkComponentsBuilder.MakeTransport());
            _converter  = new Lazy <IGelfConverter>(() => sinkComponentsBuilder.MakeGelfConverter());
        }
Beispiel #10
0
        /// <summary>
        /// Graylogs the specified options.
        /// </summary>
        /// <param name="loggerSinkConfiguration">The logger sink configuration.</param>
        /// <param name="options">The options.</param>
        /// <returns></returns>
        public static LoggerConfiguration Graylog(this LoggerSinkConfiguration loggerSinkConfiguration,
                                                  GraylogSinkOptions options
                                                  )
        {
            var sink = options.UseBatchMode
                ? new GraylogPeriodicBatchSink(options)
                : (ILogEventSink) new GraylogSink(options);

            return(loggerSinkConfiguration.Sink(sink, options.MinimumLogEventLevel));
        }
        public static IGelfConverter FromOptions(GraylogSinkOptions options)
        {
            var hostName = Dns.GetHostName();
            var builders = new Dictionary <BuilderType, Lazy <IMessageBuilder> >
            {
                [BuilderType.Exception] =
                    new Lazy <IMessageBuilder>(() => new ExceptionMessageBuilder(hostName, options)),
                [BuilderType.Message] =
                    new Lazy <IMessageBuilder>(() => new GelfMessageBuilder(hostName, options))
            };

            return(new GelfConverter(builders));
        }
Beispiel #12
0
        public GraylogSink(GraylogSinkOptions options)
        {
            _transport = MakeTransport(options);

            string hostName = Dns.GetHostName();

            IDictionary <BuilderType, Lazy <IMessageBuilder> > builders = new Dictionary <BuilderType, Lazy <IMessageBuilder> >
            {
                [BuilderType.Exception] = new Lazy <IMessageBuilder>(() => new ExceptionMessageBuilder(hostName, options)),
                [BuilderType.Message]   = new Lazy <IMessageBuilder>(() => new GelfMessageBuilder(hostName, options))
            };

            _converter = options.GelfConverter ?? new GelfConverter(builders);
        }
Beispiel #13
0
        public GraylogSink(GraylogSinkOptions options)
        {
            _transport = options.Transport;

            if (_transport == null)
            {
                if (options.UseHttpTransport)
                {
                    _converter = new HttpGelfConverter(options.Facility, options.ShortMessageMaxLength);
                    _transport = new HttpTransport(options.HostnameOrAdress);   // should be in the form http://HostNameOrIp:Port//Gelf
                }
                else
                {
                    IDnsInfoProvider dns        = new DnsWrapper();
                    IPAddress[]      ipAddreses = Task.Run(() => dns.GetHostAddresses(options.HostnameOrAdress)).Result;

                    IPAddress ipAdress = ipAddreses.FirstOrDefault(c => c.AddressFamily == AddressFamily.InterNetwork);

                    var ipEndpoint = new IPEndPoint(ipAdress, options.Port);

                    IDataToChunkConverter chunkConverter = new DataToChunkConverter(new ChunkSettings
                    {
                        MessageIdGeneratorType = options.MessageGeneratorType
                    }, new MessageIdGeneratorResolver());

                    var client = new UdpTransportClient(ipEndpoint);
                    _transport = new UdpTransport(client, chunkConverter);
                }
            }

            string hostName = Dns.GetHostName();

            IDictionary <BuilderType, IMessageBuilder> builders = new Dictionary <BuilderType, IMessageBuilder>
            {
                [BuilderType.Exception] = new ExceptionMessageBuilder(hostName, options),
                [BuilderType.Message]   = new GelfMessageBuilder(hostName, options)
            };

            _converter = options.GelfConverter ?? new GelfConverter(builders);
        }
 public GraylogPeriodicBatchSink(GraylogSinkOptions options)
     : base(options.BatchSizeLimit, options.Period)
 {
     transport = new LazyRetry <ITransport>(() => TransportFactory.FromOptions(options));
     converter = options.GelfConverter ?? GelfConverterFactory.FromOptions(options);
 }
 public GraylogSink(GraylogSinkOptions options)
 {
     transport = new LazyRetry <ITransport>(() => TransportFactory.FromOptions(options));
     converter = options.GelfConverter ?? GelfConverterFactory.FromOptions(options);
 }