本文整理汇总了C#中LoggerConfiguration.CreateLogger方法的典型用法代码示例。如果您正苦于以下问题:C# LoggerConfiguration.CreateLogger方法的具体用法?C# LoggerConfiguration.CreateLogger怎么用?C# LoggerConfiguration.CreateLogger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LoggerConfiguration
的用法示例。
在下文中一共展示了LoggerConfiguration.CreateLogger方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Logger
/// <summary>
/// Write log events to a sub-logger, where further processing may occur. Events through
/// the sub-logger will be constrained by filters and enriched by enrichers that are
/// active in the parent. A sub-logger cannot be used to log at a more verbose level, but
/// a less verbose level is possible.
/// </summary>
/// <param name="configureLogger">An action that configures the sub-logger.</param>
/// <returns>Configuration object allowing method chaining.</returns>
public LoggerConfiguration Logger(
Action<LoggerConfiguration> configureLogger)
{
if (configureLogger == null) throw new ArgumentNullException("configureLogger");
var lc = new LoggerConfiguration();
configureLogger(lc);
return Sink(new CopyingSink((ILogEventSink)lc.CreateLogger()));
}
示例2: ShouldCreateInstanceOfLogger
public void ShouldCreateInstanceOfLogger()
{
var loggerConfiguration = new LoggerConfiguration();
loggerConfiguration.WriteTo.SizeRollingFile(new CompactJsonFormatter(), "c:\\logs\\Log-{{Date}}.json", retainedFileDurationLimit: TimeSpan.FromDays(3));
var logger = loggerConfiguration.CreateLogger();
Assert.IsNotNull(logger);
}
示例3: CreateLoggerThatCrashes
private static ILogger CreateLoggerThatCrashes()
{
var loggerConfig = new LoggerConfiguration()
.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri("http://localhost:31234"))
{
AutoRegisterTemplate = true,
TemplateName = "crash"
});
return loggerConfig.CreateLogger();
}
开发者ID:alexvaluyskiy,项目名称:serilog-sinks-elasticsearch,代码行数:11,代码来源:SendsTemplateHandlesUnavailableServerTests.cs
示例4: DoRegister
private void DoRegister()
{
_templateExistsReturnCode = 200;
_options.AutoRegisterTemplate = true;
var loggerConfig = new LoggerConfiguration()
.MinimumLevel.Debug()
.Enrich.WithMachineName()
.WriteTo.ColoredConsole()
.WriteTo.Elasticsearch(_options);
var logger = loggerConfig.CreateLogger();
using (logger as IDisposable)
{
logger.Error("Test exception. Should not contain an embedded exception object.");
}
}
示例5: SetUp
private Tuple<SerilogLogger, SerilogSink> SetUp(LogLevel logLevel)
{
var sink = new SerilogSink();
var config = new LoggerConfiguration()
.Enrich.WithMachineName()
.Enrich.WithProcessId()
.Enrich.WithThreadId()
.WriteTo.Sink(sink);
SetMinLevel(config, logLevel);
var provider = new SerilogLoggerProvider(config.CreateLogger());
var logger = (SerilogLogger)provider.CreateLogger(Name);
return new Tuple<SerilogLogger, SerilogSink>(logger, sink);
}
示例6: SendsTemplateTests
public SendsTemplateTests()
{
_options.AutoRegisterTemplate = true;
var loggerConfig = new LoggerConfiguration()
.MinimumLevel.Debug()
.Enrich.WithMachineName()
.WriteTo.ColoredConsole()
.WriteTo.Elasticsearch(_options);
var logger = loggerConfig.CreateLogger();
using (logger as IDisposable)
{
logger.Error("Test exception. Should not contain an embedded exception object.");
}
this._seenHttpPosts.Should().NotBeNullOrEmpty().And.HaveCount(1);
this._seenHttpPuts.Should().NotBeNullOrEmpty().And.HaveCount(1);
_templatePut = this._seenHttpPuts[0];
}
示例7: TemplateMatchTests
public TemplateMatchTests()
{
_options.AutoRegisterTemplate = true;
_options.IndexFormat = "dailyindex-{0:yyyy.MM.dd}-mycompany";
_options.TemplateName = "dailyindex-logs-template";
var loggerConfig = new LoggerConfiguration()
.MinimumLevel.Debug()
.Enrich.WithMachineName()
.WriteTo.ColoredConsole()
.WriteTo.Elasticsearch(_options);
var logger = loggerConfig.CreateLogger();
using (logger as IDisposable)
{
logger.Error("Test exception. Should not contain an embedded exception object.");
}
this._seenHttpPosts.Should().NotBeNullOrEmpty().And.HaveCount(1);
this._seenHttpPuts.Should().NotBeNullOrEmpty().And.HaveCount(1);
this._seenHttpHeads.Should().NotBeNullOrEmpty().And.HaveCount(1);
_templatePut = this._seenHttpPuts[0];
}
示例8: ELKIntegration
public void ELKIntegration()
{
var configuration = new LoggerConfiguration().WriteTo.ELKBulk(new SinkOptions { Url = "http://vm-elk:8080/logs/", IndexTemplate = "test-", Period = TimeSpan.FromSeconds(1)});
Debugging.SelfLog.Out = Console.Out;
var logger = configuration.CreateLogger();
Log.Logger = logger;
Log.Information("Test record");
Log.Error(new Exception("Test exception"), "Exception test");
((IDisposable)logger).Dispose();
}
示例9: ThrowAndLogAndCatchBulkOutput
public void ThrowAndLogAndCatchBulkOutput(string exceptionMessage)
{
var loggerConfig = new LoggerConfiguration()
.MinimumLevel.Debug()
.Enrich.WithMachineName()
.WriteTo.ColoredConsole()
.WriteTo.Elasticsearch(_options);
var logger = loggerConfig.CreateLogger();
using (logger as IDisposable)
{
try
{
try
{
throw new Exception("inner most exception");
}
catch (Exception e)
{
var innerException = new NastyException("nasty inner exception", e);
throw new Exception(exceptionMessage, innerException);
}
}
catch (Exception e)
{
logger.Error(e, "Test exception. Should contain an embedded exception object.");
}
logger.Error("Test exception. Should not contain an embedded exception object.");
}
var postedEvents = GetPostedLogEvents(expectedCount: 2);
Console.WriteLine("BULK OUTPUT BEGIN ==========");
foreach (var post in _seenHttpPosts)
Console.WriteLine(post);
Console.WriteLine("BULK OUTPUT END ============");
var firstEvent = postedEvents[0];
firstEvent.Exceptions.Should().NotBeNull().And.HaveCount(3);
firstEvent.Exceptions[0].Message.Should().NotBeNullOrWhiteSpace()
.And.Be(exceptionMessage);
var realException = firstEvent.Exceptions[0];
realException.ExceptionMethod.Should().NotBeNull();
realException.ExceptionMethod.Name.Should().NotBeNullOrWhiteSpace();
realException.ExceptionMethod.AssemblyName.Should().NotBeNullOrWhiteSpace();
realException.ExceptionMethod.AssemblyVersion.Should().NotBeNullOrWhiteSpace();
realException.ExceptionMethod.ClassName.Should().NotBeNullOrWhiteSpace();
realException.ExceptionMethod.Signature.Should().NotBeNullOrWhiteSpace();
realException.ExceptionMethod.MemberType.Should().BeGreaterThan(0);
var nastyException = firstEvent.Exceptions[1];
nastyException.Depth.Should().Be(1);
nastyException.Message.Should().Be("nasty inner exception");
nastyException.HelpUrl.Should().Be("help url");
nastyException.StackTraceString.Should().Be("stack trace string");
nastyException.RemoteStackTraceString.Should().Be("remote stack trace string");
nastyException.RemoteStackIndex.Should().Be(1);
nastyException.HResult.Should().Be(123123);
nastyException.Source.Should().Be("source");
nastyException.ClassName.Should().Be("classname nasty exception");
//nastyException.WatsonBuckets.Should().BeEquivalentTo(new byte[] {1,2,3});
var secondEvent = postedEvents[1];
secondEvent.Exceptions.Should().BeNullOrEmpty();
}
开发者ID:alexvaluyskiy,项目名称:serilog-sinks-elasticsearch,代码行数:64,代码来源:ElasticsearchSinkUniformityTestsBase.cs
示例10: CreateLoggerThrowsIfCalledMoreThanOnce
public void CreateLoggerThrowsIfCalledMoreThanOnce()
{
var loggerConfiguration = new LoggerConfiguration();
loggerConfiguration.CreateLogger();
Assert.Throws<InvalidOperationException>(() => loggerConfiguration.CreateLogger());
}
示例11: WhenLoggerCreated
protected void WhenLoggerCreated()
{
var loggerConfig = new LoggerConfiguration()
.WriteTo.Trace()
.MinimumLevel.Verbose();
loggerConfig.WriteTo.AmazonKinesis(
kinesisClient: Client,
streamName: StreamName,
period: ThrottleTime,
bufferBaseFilename: BufferBaseFileName,
onLogSendError: OnLogSendError
);
Logger = loggerConfig.CreateLogger();
}