本文整理汇总了C#中ILoggerFactory.AddTraceSource方法的典型用法代码示例。如果您正苦于以下问题:C# ILoggerFactory.AddTraceSource方法的具体用法?C# ILoggerFactory.AddTraceSource怎么用?C# ILoggerFactory.AddTraceSource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ILoggerFactory
的用法示例。
在下文中一共展示了ILoggerFactory.AddTraceSource方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Configure
public void Configure(IApplicationBuilder app,
IHostingEnvironment env,
ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(minLevel:LogLevel.Verbose);
app.UseStaticFiles();
app.UseMvc();
// Create a catch-all response
app.Run(async (context) =>
{
var logger = loggerFactory.CreateLogger("Catchall Endpoint");
logger.LogInformation("No endpoint found for request {path}", context.Request.Path);
await context.Response.WriteAsync("No endpoint found - try /api/todo.");
});
loggerFactory.MinimumLevel = LogLevel.Debug;
#if DNX451
var sourceSwitch = new SourceSwitch("LoggingSample");
sourceSwitch.Level = SourceLevels.Critical;
loggerFactory.AddTraceSource(sourceSwitch,
new ConsoleTraceListener(false));
loggerFactory.AddTraceSource(sourceSwitch,
new EventLogTraceListener("Application"));
#endif
}
示例2: ConfigureTraceLogging
public void ConfigureTraceLogging(IApplicationBuilder app,
ILoggerFactory loggerFactory)
{
loggerFactory.MinimumLevel = LogLevel.Debug;
#if DNX451
var sourceSwitch = new SourceSwitch("LoggingSample");
sourceSwitch.Level = SourceLevels.Critical;
loggerFactory.AddTraceSource(sourceSwitch,
new ConsoleTraceListener(false));
loggerFactory.AddTraceSource(sourceSwitch,
new EventLogTraceListener("Application"));
#endif
app.UseRequestLogger();
app.Run(async context =>
{
if (context.Request.Path.Value.Contains("boom"))
{
throw new Exception("boom!");
}
await context.Response.WriteAsync("Hello World!");
});
}
示例3: Configure
public void Configure(IApplicationBuilder app,
IHostingEnvironment env,
ILoggerFactory loggerFactory)
{
loggerFactory
.WithFilter(new FilterLoggerSettings
{
{ "Microsoft", LogLevel.Warning },
{ "System", LogLevel.Warning },
{ "ToDoApi", LogLevel.Debug }
})
.AddConsole();
// add Trace Source logging
var testSwitch = new SourceSwitch("sourceSwitch", "Logging Sample");
testSwitch.Level = SourceLevels.Warning;
loggerFactory.AddTraceSource(testSwitch,
new TextWriterTraceListener(writer: Console.Out));
app.UseStaticFiles();
app.UseMvc();
// Create a catch-all response
app.Run(async (context) =>
{
if (context.Request.Path.Value.Contains("boom"))
{
throw new Exception("boom!");
}
var logger = loggerFactory.CreateLogger("Catchall Endpoint");
logger.LogInformation("No endpoint found for request {path}", context.Request.Path);
await context.Response.WriteAsync("No endpoint found - try /api/todo.");
});
}
示例4: Configure
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
// This would prevent TextWriterTraceListener from buffering trace messages but cause
// it to flush them as each trace message is sent to listener
if (env.IsDevelopment())
{
Trace.AutoFlush = true;
}
var listener = new TextWriterTraceListener("AspNet5LoggingService.txt");
listener.Filter = new SourceFilter("AspNet5LoggingService");
loggerFactory.AddTraceSource(
new SourceSwitch("AspNet5LoggingSwitch", "Verbose"),
listener
);
app.UseIISPlatformHandler();
app.UseStaticFiles();
app.UseMvc();
}
示例5: Startup
public Startup(IHostingEnvironment env, ILoggerFactory loggerFactory)
{
var builder = new ConfigurationBuilder()
.AddJsonFile("config.json")
.AddJsonFile($"config.{env.EnvironmentName}.json", optional: true);
if (env.IsDevelopment())
{
// For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
builder.AddUserSecrets();
loggerFactory.AddDebug();
loggerFactory.MinimumLevel = LogLevel.Debug;
}
builder.AddEnvironmentVariables();
Configuration = builder.Build();
_environment = env;
LoggerFactory = loggerFactory;
loggerFactory.AddConsole();
#if DNX451
int io, worker;
ThreadPool.GetMinThreads(out worker, out io);
Console.WriteLine("Startup min worker thread {0}, min io thread {1}", worker, io);
ThreadPool.GetMaxThreads(out worker, out io);
Console.WriteLine("Startup max worker thread {0}, max io thread {1}", worker, io);
ThreadPool.SetMaxThreads(32767, 1000);
ThreadPool.SetMinThreads(50, 50);
ThreadPool.GetMinThreads(out worker, out io);
Console.WriteLine("Startup min worker thread {0}, min io thread {1}", worker, io);
ThreadPool.GetMaxThreads(out worker, out io);
Console.WriteLine("Startup max worker thread {0}, max io thread {1}", worker, io);
var sourceSwitch = new SourceSwitch("chatle");
loggerFactory.AddTraceSource(sourceSwitch, new ConsoleTraceListener());
#endif
}