本文整理汇总了C#中ILoggerFactory.AddNLog方法的典型用法代码示例。如果您正苦于以下问题:C# ILoggerFactory.AddNLog方法的具体用法?C# ILoggerFactory.AddNLog怎么用?C# ILoggerFactory.AddNLog使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ILoggerFactory
的用法示例。
在下文中一共展示了ILoggerFactory.AddNLog方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Configure
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
#if DNX451
var config = new LoggingConfiguration();
// Step 2. Create targets and add them to the configuration
var consoleTarget = new ColoredConsoleTarget();
config.AddTarget("console", consoleTarget);
consoleTarget.Layout = @"${date:format=HH\\:MM\\:ss} ${ndc} ${logger} ${message} ";
var rule1 = new LoggingRule("*", NLog.LogLevel.Debug, consoleTarget);
config.LoggingRules.Add(rule1);
loggerFactory.AddNLog(new global::NLog.LogFactory(config));
#endif
app.UseErrorPage()
.UseStaticFiles()
.UseIdentity()
.UseFacebookAuthentication()
.UseGoogleAuthentication()
.UseTwitterAuthentication()
.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller}/{action}/{id?}",
defaults: new { controller = "Home", action = "Index" });
});
//Populates the Admin user and role
SampleData.InitializeIdentityDatabaseAsync(app.ApplicationServices).Wait();
}
示例2: 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();
app.UseIISPlatformHandler();
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.");
});
//add NLog to aspnet5
loggerFactory.AddNLog();
//configure nlog.config in your project root
env.ConfigureNLog("nlog.config");
}
示例3: 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)
{
//add NLog to ASP.NET Core
loggerFactory.AddNLog();
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
示例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)
{
//add NLog to ASP.NET Core
loggerFactory.AddNLog();
//needed for non-NETSTANDARD platforms: configure nlog.config in your project root
env.ConfigureNLog("nlog.config");
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseApplicationInsightsRequestTelemetry();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseApplicationInsightsExceptionTelemetry();
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
示例5: NLogDemo
public NLogDemo() {
_logFactory = new LoggerFactory();
LoggingConfiguration config = new LoggingConfiguration();
ColoredConsoleTarget consoleTarget = new ColoredConsoleTarget();
config.AddTarget("console", consoleTarget);
LoggingRule rule1 = new LoggingRule("*", NLog.LogLevel.Trace, consoleTarget);
config.LoggingRules.Add(rule1);
LogFactory factory = new LogFactory(config);
_logFactory.AddNLog(factory);
}
示例6: Configure
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
// add NLog for logging
loggerFactory.AddNLog(new LogFactory(new NLog.Config.XmlLoggingConfiguration(logConfigurationFile)));
_log = loggerFactory.CreateLogger<Startup>();
// generate some log output
_log.LogInformation("Happy table logging!");
_log.LogInformation(string.Format("Log configuration: {0}", logConfigurationFile));
app.UseIISPlatformHandler();
app.Run(async (context) =>
{
await context.Response.WriteAsync("Hello World!");
});
}
示例7: RegisterServices
public static void RegisterServices(Container container, ILoggerFactory loggerFactory) {
loggerFactory.AddNLog();
// NOTE: To enable redis, please uncomment the RedisConnectionString string in the web.config
if (Settings.Current.EnableRedis) {
var muxer = ConnectionMultiplexer.Connect(Settings.Current.RedisConnectionString);
container.RegisterSingleton(muxer);
container.RegisterSingleton<ICacheClient, RedisHybridCacheClient>();
container.RegisterSingleton<IQueue<ValuesPost>>(() => new RedisQueue<ValuesPost>(muxer, behaviors: container.GetAllInstances<IQueueBehavior<ValuesPost>>()));
container.RegisterSingleton<IQueue<WorkItemData>>(() => new RedisQueue<WorkItemData>(muxer, behaviors: container.GetAllInstances<IQueueBehavior<WorkItemData>>(), workItemTimeout: TimeSpan.FromHours(1)));
container.RegisterSingleton<IMessageBus>(() => new RedisMessageBus(muxer.GetSubscriber(), serializer: container.GetInstance<ISerializer>()));
} else {
var logger = loggerFactory.CreateLogger<Bootstrapper>();
logger.Warn().Message("Redis is NOT enabled.").Write();
}
}
示例8: Configure
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
#if DNX451
var config = new LoggingConfiguration();
// Step 2. Create targets and add them to the configuration
var consoleTarget = new ColoredConsoleTarget();
config.AddTarget("console", consoleTarget);
consoleTarget.Layout = @"${date:format=HH\\:MM\\:ss} ${ndc} ${logger} ${message} ";
var rule1 = new LoggingRule("*", NLog.LogLevel.Debug, consoleTarget);
config.LoggingRules.Add(rule1);
loggerFactory.AddNLog(new global::NLog.LogFactory(config));
#endif
app.UseDeveloperExceptionPage()
.UseStaticFiles()
.UseIdentity()
.UseFacebookAuthentication(options =>
{
options.AppId = "901611409868059";
options.AppSecret = "4aa3c530297b1dcebc8860334b39668b";
})
.UseGoogleAuthentication(options =>
{
options.ClientId = "514485782433-fr3ml6sq0imvhi8a7qir0nb46oumtgn9.apps.googleusercontent.com";
options.ClientSecret = "V2nDD9SkFbvLTqAUBWBBxYAL";
})
.UseTwitterAuthentication(options =>
{
options.ConsumerKey = "BSdJJ0CrDuvEhpkchnukXZBUv";
options.ConsumerSecret = "xKUNuKhsRdHD03eLn67xhPAyE1wFFEndFo1X2UJaK2m1jdAxf4";
})
.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller}/{action}/{id?}",
defaults: new { controller = "Home", action = "Index" });
});
//Populates the Admin user and role
SampleData.InitializeIdentityDatabaseAsync(app.ApplicationServices).Wait();
}
示例9: 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.AddNLog();
env.ConfigureNLog("nlog.config");
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseExecuteTime();
app.UseMvc();
}
示例10: Configure
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddNLog(Configuration);
app.AddNLogWeb();
app
.UseIISPlatformHandler()
.UseApplicationInsightsRequestTelemetry()
.UseApplicationInsightsExceptionTelemetry()
.UseApiExceptionResponse(env.IsDevelopment() || env.IsStaging());
var virtualPath = Environment.GetEnvironmentVariable("VIRTUAL_PATH");
if (string.IsNullOrEmpty(virtualPath) == false)
app.Map(virtualPath, x => ConfigureInternal(x, env, loggerFactory));
else
ConfigureInternal(app, env, loggerFactory);
app.Map("/throw", throwApp => throwApp.Run(context =>
{
throw new Exception("Test Exception",
new Exception("Test Inner Exception",
new Exception("Test Inner Inner Exception")));
}));
}
示例11: 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.AddNLog();
app.UseRequestIPMiddleware();
InitializeNetCoreBBSDatabase(app.ApplicationServices);
app.UseDeveloperExceptionPage();
app.UseStaticFiles();
app.UseIdentity();
app.UseStatusCodePages();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "areaRoute",
template: "{area:exists}/{controller}/{action}",
defaults: new { action = "Index" });
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
示例12: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
this.loggerFactory = new LoggerFactory();
loggerFactory.AddNLog();
services.AddSingleton<ILoggerFactory>(loggerFactory);
// Add framework services.
services.AddMvc()
.AddMvcOptions(o => { o.Filters.Add(new GlobalExceptionFilter(loggerFactory)); })
.AddViewLocalization()
.AddDataAnnotationsLocalization()
.AddFluentValidation(cfg => { cfg.RegisterValidatorsFromAssemblyContaining<ICommand>(); });
// Must be included .AddMvc
services.Configure<RazorViewEngineOptions>(options =>
{
options.ViewLocationExpanders.Add(new FeatureLocationExpander());
});
services.AddLocalization(options => options.ResourcesPath = "Resources");
var mapper = new MapperConfiguration(cfg =>
cfg.AddProfiles(new[]
{
"SandboxCore.Queries",
"SandboxCore.Commands"
})).CreateMapper();
services.AddSingleton<IMapper>(mapper);
var connection = @"Server=(localdb)\mssqllocaldb;Database=SandboxCore;Trusted_Connection=True;";
services.AddDbContext<CommandDbContext>(options => options.UseSqlServer(connection));
services.AddDbContext<QueryDbContext>(options => options.UseSqlServer(connection));
//
// Mediator pattern
//
services.AddScoped<SingleInstanceFactory>(p => t => p.GetRequiredService(t));
services.AddScoped<MultiInstanceFactory>(p => t => p.GetRequiredServices(t));
// Use Scrutor to scan and register all classes as their implemented interfaces.
services.Scan(scan => scan
.FromAssembliesOf(typeof(IMediator), typeof(Handler))
.AddClasses()
.AsImplementedInterfaces());
//
// CommandDispatcher and QueryDispatcher
//
services.Scan(scan => scan
.FromAssembliesOf(typeof(IQueryHandler<,>), typeof(ICommandHandler<>))
.AddClasses()
.AsImplementedInterfaces());
}
示例13: Configure
/// <summary>
/// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
/// </summary>
/// <param name="app"></param>
/// <param name="env"></param>
/// <param name="loggerFactory"></param>
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddNLog();
try
{
using (var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>()
.CreateScope())
{
serviceScope.ServiceProvider.GetService<BddContext>()
.Database.Migrate();
serviceScope.ServiceProvider.GetService<ApplicationDbContext>()
.Database.Migrate();
serviceScope.ServiceProvider.GetService<BddContext>().EnsureSeedData();
}
}
catch { }
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
}
app.UseDefaultFiles();
app.UseStaticFiles();
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});
app.UseIdentity();
app.UseOAuthValidation();
app.UseOpenIddict();
app.UseGoogleAuthentication(new GoogleOptions()
{
ClientId = Configuration["GOOGLE_CLIENT_ID"],
ClientSecret = Configuration["GOOGLE_CLIENT_SECRET"]
});
app.UseFacebookAuthentication(new FacebookOptions()
{
AppId = Configuration["FACEBOOK_APP_ID"],
AppSecret = Configuration["FACEBOOK_SECRET_ID"]
});
app.UseMiddleware<WebAPILoggerMiddleware>();
app.UseMvc(routes =>
{
routes.MapRoute("journee",
template: "Journee/Index/{equipe}/{idJournee}", defaults: new { controller = "Journee", action="Index", equipe="equipe1", idJournee = 1});
routes.MapRoute("actu",
template: "Journee/Detail/{url}", defaults: new { controller = "Journee", action = "Index", equipe = "equipe1", idJournee = 1 });
routes.MapRoute(
name: "default",
template: "{controller=Actu}/{action=Index}/{id?}");
});
app.UseSwagger();
app.UseSwaggerUi();
app.AddNLogWeb();
using (var context = new ApplicationDbContext(app.ApplicationServices.GetRequiredService<DbContextOptions<ApplicationDbContext>>()))
{
context.Database.EnsureCreated();
var applications = context.Set<OpenIddictApplication>();
// Add Mvc.Client to the known applications.
if (!applications.Any())
{
// Note: when using the introspection middleware, your resource server
// MUST be registered as an OAuth2 client and have valid credentials.
//
// context.Applications.Add(new OpenIddictApplication {
// Id = "resource_server",
// DisplayName = "Main resource server",
// Secret = Crypto.HashPassword("secret_secret_secret"),
// Type = OpenIddictConstants.ClientTypes.Confidential
// });
applications.Add(new OpenIddictApplication
{
ClientId = "xamarin-auth",
ClientSecret = Crypto.HashPassword(Configuration["OPENIDDICT_CLIENT_SECRET"]),
DisplayName = "HOFC",
LogoutRedirectUri = "https://local.webhofc.fr/",
RedirectUri = "urn:ietf:wg:oauth:2.0:oob",
//.........这里部分代码省略.........