Exemplo n.º 1
0
        /// <inheritdoc />
        protected override void InitializeTarget()
        {
            var customerToken = CustomerToken?.Render(LogEventInfo.CreateNullEvent());

            if (!string.IsNullOrWhiteSpace(customerToken))
            {
                LogglyConfig.Instance.CustomerToken = customerToken;

                var applicationName = ApplicationName?.Render(LogEventInfo.CreateNullEvent());
                if (!string.IsNullOrWhiteSpace(applicationName))
                {
                    LogglyConfig.Instance.ApplicationName = applicationName;
                }
            }

            var endPointHostName = EndpointHostname?.Render(LogEventInfo.CreateNullEvent());

            if (!string.IsNullOrWhiteSpace(endPointHostName))
            {
                var endpointPort = EndpointPort?.Render(LogEventInfo.CreateNullEvent());
                if (!int.TryParse(endpointPort ?? string.Empty, out var endpointPortNumber))
                {
                    endpointPortNumber = 0; // Let Loggly guess from LogTransport-enum
                }

                var forwardedForIp = ForwardedForIp?.Render(LogEventInfo.CreateNullEvent());
                if (string.IsNullOrEmpty(forwardedForIp))
                {
                    forwardedForIp = null;
                }

                LogglyConfig.Instance.Transport = new TransportConfiguration()
                {
                    EndpointHostname = endPointHostName,
                    EndpointPort     = endpointPortNumber,
                    LogTransport     = LogTransport,
                    ForwardedForIp   = forwardedForIp,
                }.GetCoercedToValidConfig();
            }

            base.InitializeTarget();
            _pendingTaskCount = 0;
            _client           = ClientFactory.Invoke();
        }