本文整理汇总了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;
}
示例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;
}
示例3: Setup
public void Setup()
{
_log = new LoggerConfiguration()
.WriteTo.Sink(new NullSink())
.CreateLogger();
_nested = _log.ForContext<NestedLoggerLatencyBenchmark>();
}
示例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;
}
示例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];
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例9: AppResourceLocator
public AppResourceLocator(ILogger logger)
{
_logger = logger.ForContext<AppResourceLocator>();
_appExecutableName =
Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().Location);
}
示例10: SerilogTraceListener
/// <summary>
/// Creates a SerilogTraceListener that uses the specified logger
/// </summary>
public SerilogTraceListener(ILogger logger)
{
this.logger = logger.ForContext<SerilogTraceListener>();
}
示例11: MimeMessageLoader
public MimeMessageLoader(MessageRepository messageRepository, ILogger logger)
{
_messageRepository = messageRepository;
_logger = logger.ForContext<MimeMessageLoader>();
}
示例12: SerilogLogWriterFactory
SerilogLogWriterFactory(ILogger logger)
{
_loggerFactory = name => logger.ForContext("SourceContext", name);
}
示例13: SerilogActorCoreEvents
public SerilogActorCoreEvents(ILogger logger)
{
_logger = logger.ForContext<IActorCoreEvents>();
}
示例14: Service
public Service(IConfig config, IOwinStartup owinStartup, ILogger logger)
{
_logger = logger.ForContext<Service>();
_config = config;
_owinStartup = owinStartup;
}
示例15: SerilogAzureEventHubActorSystemEvents
public SerilogAzureEventHubActorSystemEvents(ILogger logger)
{
_logger = logger.ForContext<IAzureEventHubActorSystemEvents>();
}
开发者ID:Rurouni,项目名称:MassiveOnlineUniversalServerEngine,代码行数:4,代码来源:SerilogAzureEventHubActorSystemEvents.cs