当前位置: 首页>>代码示例>>C#>>正文


C# LogEventLevel类代码示例

本文整理汇总了C#中LogEventLevel的典型用法代码示例。如果您正苦于以下问题:C# LogEventLevel类的具体用法?C# LogEventLevel怎么用?C# LogEventLevel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


LogEventLevel类属于命名空间,在下文中一共展示了LogEventLevel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WriteLog

        public void WriteLog(ICorrelation correlation, LogEventLevel eventLevel, Exception exception, string formatMessage, params object[] args)
        {
            if (log == null)
            {
                log = loggerRepository.GetLogger(sourceType);
            }

            if (eventLevel == LogEventLevel.Verbose && !log.IsDebugEnabled)
            {
                return;
            }

            if (args != null && args.Length != 0)
            {
                formatMessage = string.Format(formatMessage, args);
            }

            log4net.Core.ILogger logger = log.Logger;

            LoggingEvent logEvent = new LoggingEvent(sourceType, logger.Repository, logger.Name, MapEventLevel(eventLevel), formatMessage, exception);

            if (correlation != null)
            {
                logEvent.Properties["CallerId"] = correlation.CallerId;
                logEvent.Properties["CorrelationId"] = correlation.CorrelationId;
            }

            logger.Log(logEvent);
        }
开发者ID:affecto,项目名称:dotnet-Logging,代码行数:29,代码来源:LogWriter.cs

示例2: Log4Net

 public static LoggerConfiguration Log4Net(
     this LoggerSinkConfiguration loggerConfiguration,
     LogEventLevel restrictedToMinimumLevel,
     IFormatProvider formatProvider)
 {
     return loggerConfiguration.Log4Net(null, restrictedToMinimumLevel, formatProvider);
 }
开发者ID:modulexcite,项目名称:serilog-sinks-log4net,代码行数:7,代码来源:LoggerConfigurationLog4NetExtensions.cs

示例3: AmazonKinesis

        /// <summary>
        /// Adds a sink that writes log events as documents to Amazon Kinesis.
        /// </summary>
        /// <param name="loggerConfiguration">The logger configuration.</param>
        /// <param name="kinesisClient"></param>
        /// <param name="streamName"></param>
        /// <param name="shardCount"></param>
        /// <param name="bufferBaseFilename"></param>
        /// <param name="bufferFileSizeLimitBytes"></param>
        /// <param name="batchPostingLimit"></param>
        /// <param name="period"></param>
        /// <param name="minimumLogEventLevel"></param>
        /// <param name="onLogSendError"></param>
        /// <returns>Logger configuration, allowing configuration to continue.</returns>
        /// <exception cref="ArgumentNullException"></exception>
        public static LoggerConfiguration AmazonKinesis(
            this LoggerSinkConfiguration loggerConfiguration,
            IAmazonKinesis kinesisClient,
            string streamName,
            int? shardCount = null,
            string bufferBaseFilename = null,
            int? bufferFileSizeLimitBytes = null,
            int? batchPostingLimit = null,
            TimeSpan? period = null,
            LogEventLevel? minimumLogEventLevel = null,
            EventHandler<LogSendErrorEventArgs> onLogSendError = null)
        {
            if (streamName == null) throw new ArgumentNullException("streamName");

            var options = new KinesisStreamSinkOptions(streamName: streamName, shardCount: shardCount)
            {
                BufferFileSizeLimitBytes = bufferFileSizeLimitBytes,
                BufferBaseFilename = bufferBaseFilename,
                Period = period ?? KinesisStreamSinkOptions.DefaultPeriod,
                BatchPostingLimit = batchPostingLimit ?? KinesisStreamSinkOptions.DefaultBatchPostingLimit,
                MinimumLogEventLevel = minimumLogEventLevel ?? LevelAlias.Minimum,
                OnLogSendError = onLogSendError
            };

            return AmazonKinesis(loggerConfiguration, options, kinesisClient);
        }
开发者ID:johncrn,项目名称:serilog-sinks-amazoncloudwatchlogs,代码行数:41,代码来源:KinesisLoggerConfigurationExtensions.cs

示例4: AzureEventHub

        /// <summary>
        /// A sink that puts log events into a provided Azure Event Hub.
        /// </summary>
        /// <param name="loggerConfiguration">The logger configuration.</param>
        /// <param name="eventHubClient">The Event Hub to use to insert the log entries to.</param>
        /// <param name="partitionKey">The partition key used to group log events in the Event Hub.</param>
        /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
        /// <param name="outputTemplate">A message template describing the format used to write to the sink.
        /// the default is "{Timestamp} [{Level}] {Message}{NewLine}{Exception}".</param>
        /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
        /// <param name="writeInBatches">Use a periodic batching sink, as opposed to a synchronous one-at-a-time sink; this alters the partition
        /// key used for the events so is not enabled by default.</param>
        /// <param name="batchPostingLimit">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>
        /// <returns>Logger configuration, allowing configuration to continue.</returns>
        /// <exception cref="ArgumentNullException">A required parameter is null.</exception>
        public static LoggerConfiguration AzureEventHub(
            this LoggerSinkConfiguration loggerConfiguration,
            EventHubClient eventHubClient,
            string partitionKey = null,
            string outputTemplate = DefaultOutputTemplate,
            IFormatProvider formatProvider = null,
            LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
            bool writeInBatches = false,
            TimeSpan? period = null,
            int? batchPostingLimit = null
            )
        {
            if (loggerConfiguration == null)
                throw new ArgumentNullException("loggerConfiguration");
            if (eventHubClient == null)
                throw new ArgumentNullException("eventHubClient");
            if (outputTemplate == null)
                throw new ArgumentNullException("outputTemplate");

            var formatter = new MessageTemplateTextFormatter(outputTemplate, formatProvider);

            var sink = writeInBatches ?
                (ILogEventSink) new AzureEventHubBatchingSink(
                    eventHubClient,
                    partitionKey ?? DefaultPartitionKey,
                    formatter,
                    batchPostingLimit ?? DefaultBatchPostingLimit,
                    period ?? DefaultPeriod) :
                new AzureEventHubSink(
                    eventHubClient,
                    partitionKey ?? DefaultPartitionKey,
                    formatter);

            return loggerConfiguration.Sink(sink, restrictedToMinimumLevel);
        }
开发者ID:bitpulse,项目名称:serilog-sinks-azureeventhub,代码行数:51,代码来源:LoggerConfigurationAzureEventHubExtensions.cs

示例5: OperationContext

        /// <summary>
        /// Initializes a new instance of the <see cref="OperationContext" /> class.
        /// </summary>
        /// <param name="logger">The logger.</param>
        /// <param name="identifier">The identifier used for the operation. If not specified, a random guid will be used.</param>
        /// <param name="description">A description for the operation.</param>
        /// <param name="level">The level used to write the operation details to the logger. By default this is the information level.</param>
        /// <param name="warnIfExceeds">Specifies a limit, if it takes more than this limit, the level will be set to warning. By default this is not used.</param>
        /// <param name="autoSucceedOnExit">Specifies whether or not the operation should be marked with an outcome of <see cref="OperationOutcome.Success"/> if it completes without exception.</param>
        /// <param name="autoFailOnException">Specifies whether or not the operation should be marked with an outcome of <see cref="OperationOutcome.Fail"/> if an exception is detected.</param>
        /// <param name="propertyBag">A colletion of additional properties to associate with the current operation. This is typically an anonymous type.</param>
        internal OperationContext(ILogger logger,
                                  LogEventLevel level,
                                  TimeSpan? warnIfExceeds,
                                  object identifier,
                                  string description,
                                  bool autoSucceedOnExit,
                                  bool autoFailOnException,
                                  object propertyBag)
        {
            _logger = logger;
            _level = level;
            _warnIfExceeds = warnIfExceeds;
            _identifier = identifier;
            _description = description;
            _autoSucceedOnExit = autoSucceedOnExit;
            _autoFailOnException = autoFailOnException;

            _operationContextBookmark = OperationLogContext.PushOperationId(identifier);

            if (propertyBag != null)
            {
                // Save the first contextual property that we set. We then dispose of this bookmark, reverting the stack to what it was previously
                _contextualPropertiesBookmark = PushProperties(propertyBag);
            }

            _logger.Write(_level, BeginOperationMessage, _identifier, _description);

            _sw = Stopwatch.StartNew();
        }
开发者ID:richiej84,项目名称:serilog,代码行数:40,代码来源:OperationContext.cs

示例6: NewRelic

        public static LoggerConfiguration NewRelic(
            this LoggerSinkConfiguration loggerSinkConfiguration,
            LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
            int batchPostingLimit = NewRelicSink.DefaultBatchPostingLimit,
            TimeSpan? period = null,
            string applicationName = null,
            string bufferBaseFilename = null,
            long? bufferFileSizeLimitBytes = null)
        {
            if (loggerSinkConfiguration == null) throw new ArgumentNullException("loggerSinkConfiguration");

            if (bufferFileSizeLimitBytes.HasValue && bufferFileSizeLimitBytes < 0)
                throw new ArgumentException("Negative value provided; file size limit must be non-negative");

            if (string.IsNullOrEmpty(applicationName))
                throw new ArgumentException("Must supply an application name");

            var defaultedPeriod = period ?? NewRelicSink.DefaultPeriod;

            ILogEventSink sink;

            if (bufferBaseFilename == null)
                sink = new NewRelicSink(applicationName, batchPostingLimit, defaultedPeriod);
            else
            {
                //sink = new DurableNewRelicSink(bufferBaseFilename, applicationName, batchPostingLimit, defaultedPeriod,
                //    bufferFileSizeLimitBytes);

                throw new NotImplementedException("DurableNewRelicSink is not implemented yet.");
            }

            return loggerSinkConfiguration.Sink(sink, restrictedToMinimumLevel);
        }
开发者ID:Applicita,项目名称:serilog-sinks-newrelic,代码行数:33,代码来源:NewRelicLoggerConfigurationExtensions.cs

示例7: OverrideScenarios

        public void OverrideScenarios(string context, bool overrideExpected, LogEventLevel expected)
        {
            var overrides = new Dictionary<string, LoggingLevelSwitch>
            {
                ["MyApp"] = new LoggingLevelSwitch(LogEventLevel.Debug),
                ["MyApp.Api.Controllers"] = new LoggingLevelSwitch(LogEventLevel.Information),
                ["MyApp.Api.Controllers.HomeController"] = new LoggingLevelSwitch(LogEventLevel.Warning),
                ["MyApp.Api"] = new LoggingLevelSwitch(LogEventLevel.Error)
            };

            var lom = new LevelOverrideMap(overrides, LogEventLevel.Fatal, null);

            LoggingLevelSwitch overriddenSwitch;
            LogEventLevel overriddenLevel;
            lom.GetEffectiveLevel(context, out overriddenLevel, out overriddenSwitch);

            if (overrideExpected)
            {
                Assert.NotNull(overriddenSwitch);
                Assert.Equal(expected, overriddenSwitch.MinimumLevel);
                Assert.Equal(LevelAlias.Minimum, overriddenLevel);
            }
            else
            {
                Assert.Equal(LogEventLevel.Fatal, overriddenLevel);
                Assert.Null(overriddenSwitch);
            }
        }
开发者ID:serilog,项目名称:serilog,代码行数:28,代码来源:LevelOverrideMapTests.cs

示例8: Raygun

        /// <summary>
        /// Adds a sink that writes log events (defaults to error and up) to the Raygun.io webservice. Properties are being send as data and the level is used as a tag.
        /// Your message is part of the custom data.
        /// </summary>
        /// <param name="loggerConfiguration">The logger configuration.</param>
        /// <param name="raygunClient">An existing configured raygun client</param>
        /// <param name="tags">Specifies the tags to include with every log message. The log level will always be included as a tag.</param>
        /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink. By default set to Error as Raygun is mostly used for error reporting.</param>
        /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">A required parameter is null.</exception>
        public static LoggerConfiguration Raygun(this LoggerSinkConfiguration loggerConfiguration, RaygunClient raygunClient, IEnumerable<string> tags, LogEventLevel restrictedToMinimumLevel = LogEventLevel.Error, IFormatProvider formatProvider = null)
        {
            if (loggerConfiguration == null) throw new ArgumentNullException(nameof(loggerConfiguration));
            if (raygunClient == null) throw new ArgumentNullException(nameof(raygunClient));

            return loggerConfiguration.Sink(new RaygunSink(formatProvider, raygunClient, tags), restrictedToMinimumLevel);
        }
开发者ID:wwwlicious,项目名称:serilog-sinks-raygun,代码行数:18,代码来源:LoggerConfigurationRaygunExtensions.cs

示例9: Email

        /// <summary>
        /// Adds a sink that sends log events via email.
        /// </summary>
        /// <param name="loggerConfiguration">The logger configuration.</param>
        /// <param name="fromEmail">The email address emails will be sent from</param>
        /// <param name="toEmail">The email address emails will be sent to</param>
        /// <param name="mailServer">The SMTP email server to use</param>
        /// <param name="networkCredential">The network credentials to use to authenticate with mailServer</param>
        /// <param name="outputTemplate">A message template describing the format used to write to the sink.
        /// the default is "{Timestamp} [{Level}] {Message}{NewLine}{Exception}".</param>
        /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
        /// <param name="batchPostingLimit">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>
        /// <returns>Logger configuration, allowing configuration to continue.</returns>
        /// <exception cref="ArgumentNullException">A required parameter is null.</exception>
        public static LoggerConfiguration Email(
            this LoggerSinkConfiguration loggerConfiguration,
            string fromEmail,
            string toEmail,
            string mailServer,
            ICredentialsByHost networkCredential,
            string outputTemplate = DefaultOutputTemplate,
            LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
            int batchPostingLimit = EmailSink.DefaultBatchPostingLimit,
            TimeSpan? period = null,
            IFormatProvider formatProvider = null)
        {
            if (loggerConfiguration == null) throw new ArgumentNullException("loggerConfiguration");
            if (fromEmail == null) throw new ArgumentNullException("fromEmail");
            if (toEmail == null) throw new ArgumentNullException("toEmail");
            if (mailServer == null) throw new ArgumentNullException("mailServer");

            
            var connectionInfo = new EmailConnectionInfo
            {
                FromEmail = fromEmail,
                ToEmail = toEmail,
                MailServer = mailServer,
                NetworkCredentials = networkCredential
            };

            return Email(loggerConfiguration, connectionInfo, outputTemplate, restrictedToMinimumLevel, batchPostingLimit, period, formatProvider);
        }
开发者ID:BugBusted,项目名称:serilog,代码行数:44,代码来源:LoggerConfigurationEmailExtensions.cs

示例10: Email

        /// <summary>
        /// Adds a sink that sends log events via email.
        /// </summary>
        /// <param name="loggerConfiguration">The logger configuration.</param>
        /// <param name="fromEmail">The email address emails will be sent from</param>
        /// <param name="toEmail">The email address emails will be sent to</param>
        /// <param name="mailServer">The SMTP email server to use</param>
        /// <param name="networkCredential">The network credentials to use to authenticate with mailServer</param>
        /// <param name="outputTemplate">A message template describing the format used to write to the sink.
        /// the default is "{Timestamp} [{Level}] {Message:l}{NewLine:l}{Exception:l}".</param>
        /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
        /// <param name="batchPostingLimit">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>
        /// <returns>Logger configuration, allowing configuration to continue.</returns>
        /// <exception cref="ArgumentNullException">A required parameter is null.</exception>
        public static LoggerConfiguration Email(
            this LoggerSinkConfiguration loggerConfiguration,
            string fromEmail, 
            string toEmail, 
            string mailServer,
            ICredentialsByHost networkCredential,
            string outputTemplate = DefaultOutputTemplate,
            LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
            int batchPostingLimit = EmailSink.DefaultBatchPostingLimit,
            TimeSpan? period = null,
            IFormatProvider formatProvider = null)
        {
            if (loggerConfiguration == null) throw new ArgumentNullException("loggerConfiguration");
            if (fromEmail == null) throw new ArgumentNullException("fromEmail");
            if (toEmail == null) throw new ArgumentNullException("toEmail");
            if (mailServer == null) throw new ArgumentNullException("mailServer");

            var defaultedPeriod = period ?? EmailSink.DefaultPeriod;

            var formatter = new MessageTemplateTextFormatter(outputTemplate, formatProvider);

            return loggerConfiguration.Sink(
                new EmailSink(fromEmail, toEmail, mailServer, networkCredential, batchPostingLimit, defaultedPeriod, formatter),
                restrictedToMinimumLevel);
        }
开发者ID:RossMerr,项目名称:serilog,代码行数:41,代码来源:LoggerConfigurationEmailExtensions.cs

示例11: LogEvent

 /// <summary>
 ///     Creates a new <see cref="LogEvent" />
 /// </summary>
 public LogEvent(DateTimeOffset timestamp, LogEventLevel level, Exception exception, string message)
 {
     Timestamp = timestamp;
     Level = level;
     Exception = exception;
     Message = message;
 }
开发者ID:artganify,项目名称:pressiah,代码行数:10,代码来源:LogEvent.cs

示例12: SignalR

        /// <summary>
        /// Adds a sink that writes log events as documents to a SignalR hub.
        /// 
        /// </summary>
        /// <param name="loggerConfiguration">The logger configuration.</param><param name="context">The hub context.</param><param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param><param name="batchPostingLimit">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>
        /// <returns>
        /// Logger configuration, allowing configuration to continue.
        /// </returns>
        /// <exception cref="T:System.ArgumentNullException">A required parameter is null.</exception>
        public static LoggerConfiguration SignalR(this LoggerSinkConfiguration loggerConfiguration, IHubContext context, LogEventLevel restrictedToMinimumLevel = LogEventLevel.Verbose, int batchPostingLimit = 5, TimeSpan? period = null, IFormatProvider formatProvider = null)
        {
            if (loggerConfiguration == null) throw new ArgumentNullException(nameof(loggerConfiguration));
            if (context == null) throw new ArgumentNullException(nameof(context));

            return loggerConfiguration.Sink(new SignalRLogSink(context, formatProvider), restrictedToMinimumLevel);
        }
开发者ID:eugene-goldberg,项目名称:StandaloneServiceTemplate,代码行数:16,代码来源:SignalRLogSinkExtensions.cs

示例13: Should_be_able_to_log_message

        public void Should_be_able_to_log_message(LogLevel logLevel, LogEventLevel logEventLevel)
        {
            _sut.Log(logLevel, () => "m");

            _logEvent.Level.Should().Be(logEventLevel);
            _logEvent.RenderMessage().Should().Be("m");
        }
开发者ID:mihasic,项目名称:LibLog,代码行数:7,代码来源:SerilogLogProviderLoggingTests.cs

示例14: MongoDBCapped

        /// <summary>
        /// Adds a sink that writes log events as documents to a MongoDb database.
        /// </summary>
        /// <param name="loggerConfiguration">The logger configuration.</param>
        /// <param name="databaseUrl">The URL of a created MongoDB collection that log events will be written to.</param>
        /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
        /// <param name="cappedMaxSizeMb">Max total size in megabytes of the created capped collection. (Default: 50mb)</param>
        /// <param name="cappedMaxDocuments">Max number of documents of the created capped collection.</param>
        /// <param name="collectionName">Name of the collection. Default is "log".</param>
        /// <param name="batchPostingLimit">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>
        /// <returns>Logger configuration, allowing configuration to continue.</returns>
        /// <exception cref="ArgumentNullException">A required parameter is null.</exception>
        public static LoggerConfiguration MongoDBCapped(
            this LoggerSinkConfiguration loggerConfiguration,
            string databaseUrl,
            LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
            long cappedMaxSizeMb = 50,
            long? cappedMaxDocuments = null,
            string collectionName = null,
            int batchPostingLimit = MongoDBSink.DefaultBatchPostingLimit,
            TimeSpan? period = null,
            IFormatProvider formatProvider = null)
        {
            if (loggerConfiguration == null) throw new ArgumentNullException("loggerConfiguration");
            if (databaseUrl == null) throw new ArgumentNullException("databaseUrl");

            var optionsBuilder = CollectionOptions.SetCapped(true).SetMaxSize(cappedMaxSizeMb * 1024 * 1024);

            if (cappedMaxDocuments.HasValue)
            {
                optionsBuilder = optionsBuilder.SetMaxDocuments(cappedMaxDocuments.Value);
            }

            var defaultedPeriod = period ?? MongoDBSink.DefaultPeriod;
            return loggerConfiguration.Sink(
                new MongoDBSink(
                    databaseUrl,
                    batchPostingLimit,
                    defaultedPeriod,
                    formatProvider,
                    collectionName ?? MongoDBSink.DefaultCollectionName,
                    optionsBuilder),
                restrictedToMinimumLevel);
        }
开发者ID:rmoudy,项目名称:serilog,代码行数:46,代码来源:LoggerConfigurationMongoDBExtensions.cs

示例15: DummyRollingFile

 public static LoggerConfiguration DummyRollingFile(
     this LoggerSinkConfiguration loggerSinkConfiguration,
     ITextFormatter formatter,
     string pathFormat,
     LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum)
 {
     return loggerSinkConfiguration.Sink(new DummyRollingFileSink(), restrictedToMinimumLevel);
 }
开发者ID:serilog,项目名称:serilog,代码行数:8,代码来源:DummyLoggerConfigurationExtensions.cs


注:本文中的LogEventLevel类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。