public static LoggerConfiguration EventGrid(
            this LoggerSinkConfiguration loggerConfiguration,
            string key                       = null,
            string topicEndpoint             = null,
            string customEventSubject        = null,
            string customEventType           = null,
            string customSubjectPropertyName = "EventSubject",
            string customTypePropertyName    = "EventType",
            CustomEventRequestAuth customEventRequestAuth = CustomEventRequestAuth.Key,
            int batchSizeLimit = EventGridSink.DefaultBatchPostingLimit,
            TimeSpan?period    = null,
            LogEventLevel restrictedToMinimumLevel = LogEventLevel.Information,
            IFormatProvider formatProvider         = null)
        {
            if (loggerConfiguration == null)
            {
                throw new ArgumentNullException("loggerConfiguration");
            }

            // allow null and pull from app configuration
            key           = key ?? ConfigurationManager.AppSettings["EventGridTopicKey"];
            topicEndpoint = topicEndpoint ?? ConfigurationManager.AppSettings["EventGridTopicUri"];

            if (string.IsNullOrWhiteSpace(key))
            {
                throw new ArgumentNullException("key");
            }

            if (string.IsNullOrWhiteSpace(topicEndpoint))
            {
                throw new ArgumentNullException("topicEndpoint");
            }

            var topicUri = new Uri(topicEndpoint);

            if (!topicUri.IsAbsoluteUri)
            {
                throw new ArgumentException("topicEndpoint must be an absolute uri");
            }

            var timePeriod = period ?? EventGridSink.DefaultPeriod;

            return(loggerConfiguration.Sink(
                       new EventGridSink(
                           formatProvider,
                           key, topicUri,
                           customEventSubject,
                           customEventType,
                           customEventRequestAuth,
                           customSubjectPropertyName,
                           customTypePropertyName,
                           batchSizeLimit,
                           timePeriod), restrictedToMinimumLevel));
        }
Ejemplo n.º 2
0
 public EventGridClient(string key,
                        Uri topicUri,
                        string customEventSubject,
                        string customEventType,
                        CustomEventRequestAuth customEventRequestAuth,
                        string customSubjectPropertyName,
                        string customTypePropertyName)
 {
     _key                       = key;
     _topicUri                  = topicUri;
     _customEventSubject        = customEventSubject;
     _customEventType           = customEventType;
     _customEventRequestAuth    = customEventRequestAuth;
     _customSubjectPropertyName = customSubjectPropertyName;
     _customTypePropertyName    = customTypePropertyName;
 }
        public EventGridSink(IFormatProvider formatProvider,
                             string key,
                             Uri topicUri,
                             string customEventSubject,
                             string customEventType,
                             CustomEventRequestAuth customEventRequestAuth,
                             string customSubjectPropertyName,
                             string customTypePropertyName,
                             int batchSizeLimit,
                             TimeSpan period) : base(batchSizeLimit, period)
        {
            if (string.IsNullOrWhiteSpace(key))
            {
                throw new ArgumentNullException("key");
            }

            _client = new EventGridClient(key, topicUri, customEventSubject, customEventType, customEventRequestAuth, customSubjectPropertyName, customTypePropertyName);
        }