예제 #1
0
        public void ConfigureLogglyClient(LogglyConfiguration logglyConfiguration)
        {
            var config = LogglyConfig.Instance;

            if (!string.IsNullOrWhiteSpace(logglyConfiguration.ApplicationName))
            {
                config.ApplicationName = logglyConfiguration.ApplicationName;
            }

            if (string.IsNullOrWhiteSpace(logglyConfiguration.CustomerToken))
            {
                throw new ArgumentNullException("CustomerToken", "CustomerToken is required");
            }

            config.CustomerToken = logglyConfiguration.CustomerToken;
            config.IsEnabled     = logglyConfiguration.IsEnabled;

            if (logglyConfiguration.Tags != null)
            {
                foreach (var tag in logglyConfiguration.Tags)
                {
                    config.TagConfig.Tags.Add(tag);
                }
            }

            config.ThrowExceptions = logglyConfiguration.ThrowExceptions;

            if (logglyConfiguration.LogTransport != TransportProtocol.Https)
            {
                config.Transport.LogTransport = (LogTransport)Enum.Parse(typeof(LogTransport), logglyConfiguration.LogTransport.ToString());
            }

            if (!string.IsNullOrWhiteSpace(logglyConfiguration.EndpointHostName))
            {
                config.Transport.EndpointHostname = logglyConfiguration.EndpointHostName;
            }

            if (logglyConfiguration.EndpointPort > 0 && logglyConfiguration.EndpointPort <= ushort.MaxValue)
            {
                config.Transport.EndpointPort = logglyConfiguration.EndpointPort;
            }

            config.Transport.IsOmitTimestamp = logglyConfiguration.OmitTimestamp;
            config.Transport = config.Transport.GetCoercedToValidConfig();
        }
        public DurableLogglySink(
            string bufferBaseFilename,
            int batchPostingLimit,
            TimeSpan period,
            long?bufferFileSizeLimitBytes,
            long?eventBodyLimitBytes,
            LoggingLevelSwitch levelControlSwitch,
            long?retainedInvalidPayloadsLimitBytes,
            int?retainedFileCountLimit              = null,
            IFormatProvider formatProvider          = null,
            LogglyConfiguration logglyConfiguration = null,
            LogIncludes includes = null)
        {
            if (bufferBaseFilename == null)
            {
                throw new ArgumentNullException(nameof(bufferBaseFilename));
            }

            //use a consistent UTF encoding with BOM so no confusion will exist when reading / deserializing
            var encoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false);

            //handles sending events to Loggly's API through LogglyClient and manages the pending list
            _shipper = new HttpLogShipper(
                bufferBaseFilename,
                batchPostingLimit,
                period,
                eventBodyLimitBytes,
                levelControlSwitch,
                retainedInvalidPayloadsLimitBytes,
                encoding,
                retainedFileCountLimit,
                logglyConfiguration);

            //writes events to the file to support connection recovery
            _sink = new RollingFileSink(
                bufferBaseFilename + "-{Date}.json",
                new LogglyFormatter(formatProvider, includes), //serializes as LogglyEvent
                bufferFileSizeLimitBytes,
                retainedFileCountLimit,
                encoding);
        }
예제 #3
0
        public HttpLogShipper(
            string bufferBaseFilename,
            int batchPostingLimit,
            TimeSpan period, long?
            eventBodyLimitBytes,
            LoggingLevelSwitch levelControlSwitch,
            long?retainedInvalidPayloadsLimitBytes,
            Encoding encoding,
            int?retainedFileCountLimit,
            LogglyConfiguration logglyConfiguration)
        {
            _batchPostingLimit      = batchPostingLimit;
            _retainedFileCountLimit = retainedFileCountLimit;

            _controlledSwitch   = new ControlledLevelSwitch(levelControlSwitch);
            _connectionSchedule = new ExponentialBackoffConnectionSchedule(period);

            if (logglyConfiguration != null)
            {
                _adapter = new LogglyConfigAdapter();
                _adapter.ConfigureLogglyClient(logglyConfiguration);
            }

            _logglyClient = new LogglyClient(); //we'll use the loggly client instead of HTTP directly

            //create necessary path elements
            var candidateSearchPath = Path.GetFileName(bufferBaseFilename) + "*.json";
            var logFolder           = Path.GetDirectoryName(candidateSearchPath);

            //Filebase is currently the only option available so we will stick with it directly (for now)
            var encodingToUse    = encoding;
            var bookmarkProvider = new FileBasedBookmarkProvider(bufferBaseFilename, _fileSystemAdapter, encoding);

            _bufferDataProvider   = new FileBufferDataProvider(bufferBaseFilename, _fileSystemAdapter, bookmarkProvider, encodingToUse, batchPostingLimit, eventBodyLimitBytes, retainedFileCountLimit);
            _invalidPayloadLogger = new InvalidPayloadLogger(logFolder, encodingToUse, _fileSystemAdapter, retainedInvalidPayloadsLimitBytes);

            _timer = new PortableTimer(c => OnTick());
            SetTimer();
        }
예제 #4
0
 /// <summary>
 /// Construct a sink that saves logs to the specified storage account. Properties are being send as data and the level is used as tag.
 /// </summary>
 /// <param name="batchSizeLimit">The maximum number of events to post in a single batch.</param>
 /// <param name="period">The time to wait between checking for event batches.</param>
 ///  <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
 /// <param name="logglyConfig">Used to configure underlying LogglyClient programmaticaly. Otherwise use app.Config.</param>
 /// <param name="includes">Decides if the sink should include specific properties in the log message</param>
 public LogglySink(IFormatProvider formatProvider, int batchSizeLimit, TimeSpan period, LogglyConfiguration logglyConfig, LogIncludes includes)
     : base(batchSizeLimit, period)
 {
     if (logglyConfig != null)
     {
         _adapter = new LogglyConfigAdapter();
         _adapter.ConfigureLogglyClient(logglyConfig);
     }
     _client    = new LogglyClient();
     _converter = new LogEventConverter(formatProvider, includes);
 }