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


C# ILoggerFactory.AddNLog方法代码示例

本文整理汇总了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();
        }
开发者ID:ruanbl,项目名称:Identity,代码行数:31,代码来源:Startup.cs

示例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");
    }
开发者ID:juri33,项目名称:FootballCoach,代码行数:26,代码来源:Startup.cs

示例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?}");
            });
        }
开发者ID:NLog,项目名称:NLog.Extensions.Logging,代码行数:32,代码来源:Startup.cs

示例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?}");
            });
        }
开发者ID:NLog,项目名称:NLog.Extensions.Logging,代码行数:36,代码来源:Startup.cs

示例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);
        }
开发者ID:EsWork,项目名称:Es.Logging,代码行数:15,代码来源:NLogDemo.cs

示例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!");
            });
        }
开发者ID:Greenliff,项目名称:NLog.Extensions.AzureTableStorage,代码行数:17,代码来源:Startup.cs

示例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();
            }
        }
开发者ID:exceptionless,项目名称:Foundatio.Samples,代码行数:18,代码来源:Bootstrapper.cs

示例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();
        }
开发者ID:leloulight,项目名称:Identity,代码行数:43,代码来源:Startup.cs

示例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();
        }
开发者ID:scheshan,项目名称:DotNetClub,代码行数:22,代码来源:Startup.cs

示例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")));
                                                       }));
        }
开发者ID:litichevskiydv,项目名称:DnxTestWebApp,代码行数:24,代码来源:Startup.cs

示例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?}");
            });
        }
开发者ID:yaozhenfa,项目名称:NETCoreBBS,代码行数:25,代码来源:Startup.cs

示例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());
        }
开发者ID:RossWhitehead,项目名称:SandboxCore,代码行数:56,代码来源:Startup.cs

示例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",
//.........这里部分代码省略.........
开发者ID:orome656,项目名称:HOFCServerNet,代码行数:101,代码来源:Startup.cs


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