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


C# ILogger.ForContext方法代码示例

本文整理汇总了C#中ILogger.ForContext方法的典型用法代码示例。如果您正苦于以下问题:C# ILogger.ForContext方法的具体用法?C# ILogger.ForContext怎么用?C# ILogger.ForContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ILogger的用法示例。


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

示例1: SetContextFromLogEvent

 private ILogger SetContextFromLogEvent(ILogger logger, LogEvent logEvent)
 {
     logger.ForContext("Timestamp", logEvent.Timestamp);
     logger.ForContext("LogSource", logEvent.LogSource);
     logger.ForContext("Thread", logEvent.Thread);
     return logger;
 }
开发者ID:njimenez,项目名称:akka.net,代码行数:7,代码来源:SerilogLogger.cs

示例2: GetProduct

 public Product GetProduct(ILogger log)
 {
     var idx = _random.Next() % _products.Count;
     var result = _products[idx];
     log.ForContext<Catalog>().Debug("Loaded {ProductId} from database in {TimeMS} ms", result.Id, (idx + 1) * 7);
     return result;
 }
开发者ID:kensykora,项目名称:serilog-generator,代码行数:7,代码来源:Catalog.cs

示例3: Setup

        public void Setup()
        {
            _log = new LoggerConfiguration()
                .WriteTo.Sink(new NullSink())
                .CreateLogger();

            _nested = _log.ForContext<NestedLoggerLatencyBenchmark>();
        }
开发者ID:serilog,项目名称:serilog,代码行数:8,代码来源:NestedLoggerLatencyBenchmark.cs

示例4: SetContextFromLogEvent

        private ILogger SetContextFromLogEvent(ILogger logger, LogEvent logEvent)
        {
            logger = logger
                      .ForContext("Timestamp", logEvent.Timestamp)
                      .ForContext("LogSource", logEvent.LogSource)
                      .ForContext("Thread", logEvent.Thread.ManagedThreadId.ToString().PadLeft(4, '0'));

            return logger;
        }
开发者ID:skotzko,项目名称:akka.net,代码行数:9,代码来源:SerilogLogger.cs

示例5: Server

        public Server(
            ServerProtocolType serverProtocolType,
            IIndex<ServerProtocolType, Func<IProtocol>> protocolFactory,
            ConnectionManager connectionManager,
            ILogger logger)
        {
            ConnectionManager = connectionManager;

            _serverProtocolType = serverProtocolType;
            Logger = logger.ForContext("ServerProtocolType", _serverProtocolType);
            ProtocolFactory = protocolFactory[_serverProtocolType];
        }
开发者ID:dahmaneaissi,项目名称:Papercut,代码行数:12,代码来源:Server.cs

示例6: Connection

        public Connection(int id, Socket client, IProtocol protocol, ILogger logger)
        {
            // Initialize members
            Id = id;
            Client = client;
            Protocol = protocol;
            Logger = logger;

            Logger.ForContext("ConnectionId", id);

            Connected = true;
            LastActivity = DateTime.Now;

            BeginReceive();

            Protocol.Begin(this);
        }
开发者ID:sravimohan,项目名称:Papercut,代码行数:17,代码来源:Connection.cs

示例7: SerilogLogger

        public SerilogLogger(
            SerilogLoggerProvider provider,
            ILogger logger = null,
            string name = null)
        {
            if (provider == null) throw new ArgumentNullException(nameof(provider));
            _provider = provider;
            _name = name;
            _logger = logger;

            // If a logger was passed, the provider has already added itself as an enricher
            _logger = _logger ?? Serilog.Log.Logger.ForContext(new[] { provider });

            if (_name != null)
            {
                _logger = _logger.ForContext(Constants.SourceContextPropertyName, name);
            }
        }
开发者ID:304NotModified,项目名称:serilog-extensions-logging,代码行数:18,代码来源:SerilogLogger.cs

示例8: Log

        static void Log(ILogger logger)
        {
            const int elapsedMs = 34;
            var position = new { Latitude = 25, Longitude = 134 };

            logger.ForContext<Program>().Debug("Processed {@Position} in {Elapsed:000} ms.", position, elapsedMs);
            logger.ForContext<Program>().Verbose("Processed {@Position} in {Elapsed:000} ms.", position, elapsedMs);
            logger.ForContext<Program>().Fatal("Processed {@Position} in {Elapsed:000} ms.", position, elapsedMs);
            logger.ForContext<Program>().Information("Processed {@Position} in {Elapsed:000} ms.", position, elapsedMs);
            logger.ForContext<Program>().Warning("Processed {@Position} in {Elapsed:000} ms.", position, elapsedMs);

            try
            {
                throw new NotImplementedException();
            }
            catch (Exception ex)
            {
                logger.ForContext<Program>().Error(ex, "Processed {@Position} in {Elapsed:000} ms.", position, elapsedMs);
            }
        }
开发者ID:shcheahgmail,项目名称:DotNetSamples,代码行数:20,代码来源:Program.cs

示例9: AppResourceLocator

 public AppResourceLocator(ILogger logger)
 {
     _logger = logger.ForContext<AppResourceLocator>();
     _appExecutableName =
         Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().Location);
 }
开发者ID:priestd09,项目名称:Papercut,代码行数:6,代码来源:AppResourceLocator.cs

示例10: SerilogTraceListener

 /// <summary>
 ///     Creates a SerilogTraceListener that uses the specified logger
 /// </summary>
 public SerilogTraceListener(ILogger logger)
 {
     this.logger = logger.ForContext<SerilogTraceListener>();
 }
开发者ID:KeithBarrows,项目名称:SerilogTraceListener,代码行数:7,代码来源:SerilogTraceListener.cs

示例11: MimeMessageLoader

 public MimeMessageLoader(MessageRepository messageRepository, ILogger logger)
 {
     _messageRepository = messageRepository;
     _logger = logger.ForContext<MimeMessageLoader>();
 }
开发者ID:Jaben,项目名称:Papercut,代码行数:5,代码来源:MimeMessageLoader.cs

示例12: SerilogLogWriterFactory

 SerilogLogWriterFactory(ILogger logger)
 {
     _loggerFactory = name => logger.ForContext("SourceContext", name);
 }
开发者ID:CharlieBP,项目名称:Topshelf,代码行数:4,代码来源:SerilogLogWriterFactory.cs

示例13: SerilogActorCoreEvents

 public SerilogActorCoreEvents(ILogger logger)
 {
     _logger = logger.ForContext<IActorCoreEvents>();
 }
开发者ID:Rurouni,项目名称:MassiveOnlineUniversalServerEngine,代码行数:4,代码来源:SerilogActorCoreEvents.cs

示例14: Service

 public Service(IConfig config, IOwinStartup owinStartup, ILogger logger)
 {
     _logger = logger.ForContext<Service>();
     _config = config;
     _owinStartup = owinStartup;
 }
开发者ID:droyad,项目名称:SbManager,代码行数:6,代码来源:Service.cs

示例15: SerilogAzureEventHubActorSystemEvents

 public SerilogAzureEventHubActorSystemEvents(ILogger logger)
 {
     _logger = logger.ForContext<IAzureEventHubActorSystemEvents>();
 }
开发者ID:Rurouni,项目名称:MassiveOnlineUniversalServerEngine,代码行数:4,代码来源:SerilogAzureEventHubActorSystemEvents.cs


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