/// <summary>
        /// Adds a non-durable sink that sends log events using HTTP POST over the network. A
        /// non-durable sink will lose data after a system or process restart.
        /// </summary>
        /// <param name="sinkConfiguration">The logger configuration.</param>
        /// <param name="requestUri">The URI the request is sent to.</param>
        /// <param name="batchPostingLimit">
        /// The maximum number of events to post in a single batch. Default value is 1000.
        /// </param>
        /// <param name="queueLimit">
        /// The maximum number of events stored in the queue in memory, waiting to be posted over
        /// the network. Default value is infinitely.
        /// </param>
        /// <param name="period">
        /// The time to wait between checking for event batches. Default value is 2 seconds.
        /// </param>
        /// <param name="textFormatter">
        /// The formatter rendering individual log events into text, for example JSON. Default
        /// value is <see cref="NormalRenderedTextFormatter"/>.
        /// </param>
        /// <param name="batchFormatter">
        /// The formatter batching multiple log events into a payload that can be sent over the
        /// network. Default value is <see cref="DefaultBatchFormatter"/>.
        /// </param>
        /// <param name="restrictedToMinimumLevel">
        /// The minimum level for events passed through the sink. Default value is
        /// <see cref="LevelAlias.Minimum"/>.
        /// </param>
        /// <param name="httpClient">
        /// A custom <see cref="IHttpClient"/> implementation. Default value is
        /// <see cref="HttpClient"/>.
        /// </param>
        /// <returns>Logger configuration, allowing configuration to continue.</returns>>
        public static LoggerConfiguration Site24x7Url(
            this LoggerSinkConfiguration sinkConfiguration,
            string requestUri,
            string minimumLogLevel = null,
            TimeSpan?period        = null,
            int batchPostingLimit  = 1,
            int?queueLimit         = null
            )

        {
            LogEventLevel restrictedToMinimumLevel = LogEventLevel.Verbose;

            if (minimumLogLevel == null)
            {
                restrictedToMinimumLevel = LogEventLevel.Verbose;
            }
            else if (minimumLogLevel == "Debug")
            {
                restrictedToMinimumLevel = LogEventLevel.Debug;
            }
            else if (minimumLogLevel == "Information")
            {
                restrictedToMinimumLevel = LogEventLevel.Information;
            }
            else if (minimumLogLevel == "Warning")
            {
                restrictedToMinimumLevel = LogEventLevel.Warning;
            }
            else if (minimumLogLevel == "Error")
            {
                restrictedToMinimumLevel = LogEventLevel.Error;
            }
            else if (minimumLogLevel == "Fatal")
            {
                restrictedToMinimumLevel = LogEventLevel.Fatal;
            }
            else
            {
                restrictedToMinimumLevel = LogEventLevel.Verbose;
            }

            if (sinkConfiguration == null)
            {
                throw new ArgumentNullException(nameof(sinkConfiguration));
            }

            // Default values
            period = period ?? TimeSpan.FromMilliseconds(0.01);
            ITextFormatter  textFormatter  = new NormalRenderedTextFormatter();
            IBatchFormatter batchFormatter = new DefaultBatchFormatter();
            IHttpClient     httpClient     = new DefaultHttpClient();

            var sink = queueLimit != null
                ? new HttpSink(requestUri, batchPostingLimit, queueLimit.Value, period.Value, textFormatter, batchFormatter, httpClient)
                : new HttpSink(requestUri, batchPostingLimit, period.Value, textFormatter, batchFormatter, httpClient);

            return(sinkConfiguration.Sink(sink, restrictedToMinimumLevel));
        }
コード例 #2
0
        static void Main(string[] args)
        {
            var r = new DefaultBatchFormatter();

            Exception ex;

            try
            {
                throw new Exception("Something went wrong, see StackTrace for more info");
            }
            catch (Exception e)
            {
                ex = e;
            }

            var credentials = new NoAuthCredentials("http://*****:*****@Position} in {Elapsed:000} ms.", position, elapsedMs);
            }

/*            log.Information("1# Logging {@Heartbeat:l} from {Computer:l}", "SomeValue", "SomeOtherValue");*/

/*            var position = new { Latitude = 25, Longitude = 134 };
 *          var exception = new {Message = ex.Message, StackTrace = ex.StackTrace};
 *          var elapsedMs = 34;*/

/*            log.Debug(@"Does this \""break\"" something?");
 *          log.Error("#2 {@Message}", exception);
 *          log.Information("3# Random message processed {@Position} in {Elapsed:000} ms.", position, elapsedMs);*/

            log.Dispose();
        }