// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory) { if (env.IsDevelopment()) { } // Enable middleware to serve generated Swagger as a JSON endpoint. app.UseSwagger(); // Enable middleware to serve swagger-ui (HTML, JS, CSS etc.), specifying the Swagger JSON endpoint. app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "TwBusManagement API V1"); c.ShowRequestHeaders(); }); System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); //这是为了防止中文乱码 loggerFactory.AddNLog(); //添加NLog env.ConfigureNLog("nlog.config"); //读取Nlog配置文件 app.UseMvc(); app.UseExceptionHandler("/Values/Error"); ////使用IdentityServer4的资源服务并配置 //app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions //{ // Authority = "http://localhost:4537/", // ApiName = "api1", // SaveToken = true, // AllowedScopes = new string[] { "offline_access" }, //添加额外的scope,offline_access为Refresh Token的获取Scope // RequireHttpsMetadata = false //}); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory _loggerFactory) { app.UseCors("AllowedCorsOrigins"); // ===== Middleware to serve generated Swagger as a JSON endpoint and serve swagger-ui ===== app.UseSwagger(); app.UseSwaggerUI(setup => { setup.SwaggerEndpoint("/swagger/v1/swagger.json", "Items API"); setup.RoutePrefix = "api"; setup.DocExpansion(DocExpansion.None); }); app.UseHttpsRedirection(); // ==== Response compression ==== app.UseResponseCompression(); app.UseMiddleware <GlobalExceptionMiddleware>(); app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapHealthChecks("hc"); endpoints.MapControllers(); }); }
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory) { app.UseAbp(); // Initializes ABP framework. if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Error"); } app.UseStaticFiles(); app.UseRouting(); app.UseAuthentication(); app.UseJwtTokenMiddleware(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapHub <AbpCommonHub>("/signalr"); endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}"); endpoints.MapControllerRoute("defaultWithArea", "{area}/{controller=Home}/{action=Index}/{id?}"); }); }
public GetCore1(Tool.SqlCore.DbHelper dbHelper, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory, Microsoft.AspNetCore.Hosting.IWebHostEnvironment env, IHttpContextAccessor context) { this.dbHelper = dbHelper; }
public TestAuthHandler( IOptionsMonitor <AuthenticationSchemeOptions> options, Microsoft.Extensions.Logging.ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock) : base(options, logger, encoder, clock) { }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory) { //loggerFactory.ConfigureNLog("nlog.config"); ////loggerFactory.AddNLog(); //添加NLog //loggerFactory.AddNLog(); //env.ConfigureNLog("nlog.config"); //将日志记录到数据库 config/NLog.config NLog.LogManager.LoadConfiguration("nlog.config").GetCurrentClassLogger(); NLog.LogManager.Configuration.Variables["connectionString"] = Configuration.GetConnectionString("DefaultConnection"); Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); //避免日志中的中文输出乱码 if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }
public void FlushAll(Microsoft.Extensions.Logging.ILoggerFactory loggerFactory) { while (acquiredLoggers.TryTake(out var logger)) { logger.Flush(loggerFactory); } }
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { //Initializes ABP framework. app.UseAbp(options => { options.UseAbpRequestLocalization = false; //used below: UseAbpRequestLocalization }); app.UseCors(DefaultCorsPolicyName); //Enable CORS! app.UseAuthentication(); app.UseJwtTokenMiddleware(); if (bool.Parse(_appConfiguration["IdentityServer:IsEnabled"])) { app.UseJwtTokenMiddleware("IdentityBearer"); app.UseIdentityServer(); } app.UseStaticFiles(); if (DatabaseCheckHelper.Exist(_appConfiguration["ConnectionStrings:Default"])) { app.UseAbpRequestLocalization(); } #if FEATURE_SIGNALR //Integrate to OWIN app.UseAppBuilder(ConfigureOwinServices); #endif //Hangfire dashboard & server (Enable to use Hangfire instead of default job manager) //app.UseHangfireDashboard("/hangfire", new DashboardOptions //{ // Authorization = new[] { new AbpHangfireAuthorizationFilter(AppPermissions.Pages_Administration_HangfireDashboard) } //}); //app.UseHangfireServer(); app.UseMvc(routes => { routes.MapRoute( name: "defaultWithArea", template: "{area}/{controller=Home}/{action=Index}/{id?}"); routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); // Enable middleware to serve generated Swagger as a JSON endpoint app.UseSwagger(); // Enable middleware to serve swagger-ui assets (HTML, JS, CSS etc.) app.UseSwaggerUI(options => { options.SwaggerEndpoint("/swagger/v1/swagger.json", "CRM API V1"); options.IndexStream = () => Assembly.GetExecutingAssembly() .GetManifestResourceStream("CRM.Web.wwwroot.swagger.ui.index.html"); }); //URL: /swagger }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure( IApplicationBuilder app, IHostingEnvironment env, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory ) { loggerFactory.UseAsHibernateLoggerFactory(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } // app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); app.UseAuthentication(); app.UseMvc( routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }
public static Microsoft.Extensions.Logging.ILoggerFactory AddSyslog(this Microsoft.Extensions.Logging.ILoggerFactory factory, string host, int port, System.Func <string, Microsoft.Extensions.Logging.LogLevel, bool> filter = null) { factory.AddProvider(new SyslogLoggerProvider(host, port, filter)); return(factory); }
public Startup(IConfiguration configuration, MsILoggerFactory loggerFactory) { Configuration = configuration; LogFactory.SetCurrent(new NetCoreLoggerFactory(loggerFactory)); _logger = LogFactory.GetCurrent().Create <Startup>(); _logger.Info("Application Startup."); }
public void CreateLogger_forwards_to_inner_factory_and_returns_adapter([Frozen] ILoggerFactory loggerFactory, NybusLoggerFactoryAdapter sut, string categoryName) { var logger = sut.CreateLogger(categoryName); Assert.That(logger, Is.InstanceOf <NybusLoggerAdapter>()); Mock.Get(loggerFactory).Verify(p => p.CreateLogger(categoryName)); }
public Repository(zModel context, Microsoft.Extensions.Logging.ILoggerFactory logger) { Type typeParameter = typeof(T); RepositoryName = typeParameter.Name; Context = context; Logger = logger.CreateLogger(RepositoryName); }
public static void UseAsHibernateLoggerFactory( this Microsoft.Extensions.Logging.ILoggerFactory loggerFactory ) { NHibernateLogger.SetLoggersFactory( new NetCoreLoggerFactory(loggerFactory) ); }
internal OwinLoggerFactory(Microsoft.Extensions.Logging.ILoggerFactory loggerFactory) { if (loggerFactory == null) { throw new ArgumentNullException(nameof(loggerFactory)); } _loggerFactory = loggerFactory; }
internal OwinLoggerFactory(Microsoft.Extensions.Logging.ILoggerFactory loggerFactory) { if (loggerFactory == null) { throw new ArgumentNullException(nameof(loggerFactory)); } _loggerFactory = loggerFactory; }
public TestAuthenticationHandler( Microsoft.Extensions.Options.IOptionsMonitor <TestAuthenticationOptions> options, Microsoft.Extensions.Logging.ILoggerFactory logger, System.Text.Encodings.Web.UrlEncoder encoder, Microsoft.AspNetCore.Authentication.ISystemClock clock ) : base(options, logger, encoder, clock) { }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory, IHostingEnvironment hostingEnvironment) { loggerFactory.AddFile(Path.Combine(hostingEnvironment.ContentRootPath, "logger.txt")); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseMvc(); }
/// <summary> /// Specifies the <see cref="MsLoggerFactory"/> to use when constructing <see cref="ILog"/> instances. /// </summary> public void UseMsFactory(MsLoggerFactory msLoggerFactory) { Guard.AgainstNull(msLoggerFactory, nameof(msLoggerFactory)); if (this.msLoggerFactory == null) { this.msLoggerFactory = msLoggerFactory; return; } throw new Exception($"Call {nameof(UseMsFactory)} has already been called."); }
public void Constructing_WhenArgumentIsNull_ThrowArgumentNullException(bool isCurrenWeatherServiceNull, bool isLoggerNull, string exceptionMessage) { ICurrentWeatherService currentWeatherService = isCurrenWeatherServiceNull ? null : TestHelper.GetCurrentWeatherServiceMock().Object; Microsoft.Extensions.Logging.ILoggerFactory logger = isLoggerNull ? null : TestHelper.GetLoggerFactoryMock().Object; ArgumentNullException ex = Assert.Throws <ArgumentNullException>(() => new CitySearchCommand(currentWeatherService, logger)); Assert.NotNull(ex); Assert.Equal(exceptionMessage, ex.Message); }
public void ExecuteAsync_WhenCalled_ReturnSuccessful() { ICurrentWeatherService currentWeatherService = TestHelper.GetCurrentWeatherServiceMock().Object; Microsoft.Extensions.Logging.ILoggerFactory loggerFactory = TestHelper.GetLoggerFactoryMock().Object; CitySearchViewModel result = new CitySearchCommand(currentWeatherService, loggerFactory) .ExecuteAsync("auditId", "Guiseley") .Result; Assert.NotNull(result); }
public NServiceBusHostedService(IStartableEndpointWithExternallyManagedContainer startableEndpoint, IServiceProvider serviceProvider, ILoggerFactory loggerFactory, DeferredLoggerFactory deferredLoggerFactory, HostAwareMessageSession hostAwareMessageSession) { this.loggerFactory = loggerFactory; this.deferredLoggerFactory = deferredLoggerFactory; this.hostAwareMessageSession = hostAwareMessageSession; this.startableEndpoint = startableEndpoint; this.serviceProvider = serviceProvider; }
public static Microsoft.Extensions.Logging.ILoggerFactory AddLog4Net(this Microsoft.Extensions.Logging.ILoggerFactory Factory, string Config = "log4net.config") { if (!Path.IsPathRooted(Config)) { var assembly = Assembly.GetEntryAssembly(); var dir = Path.GetDirectoryName(assembly.Location); Config = Path.Combine(dir, Config); } Factory.AddProvider(new Log4NetLoggerProvider(Config)); return(Factory); }
public DeviceMonitorService(IServiceProvider services, IGrainIdentity id, Silo silo, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory, IGrainFactory grainFactory, MsvClientCtrlSDK msv, RestClient client) : base(id, silo, loggerFactory) { Logger = Sobey.Core.Log.LoggerManager.GetLogger("MonitorService"); _lstTimerScheduleDevice = new List <ChannelInfo>(); _timer = null; _msvClient = msv; _restClient = client; _grainFactory = grainFactory; _grainKey = string.Empty; }
private void ConfigureMetrics(Microsoft.Extensions.Logging.ILoggerFactory loggerFactory, IServiceCollection serviceCollection) { var configuration = new ConfigurationBuilder() .AddEnvironmentVariables() .Build(); var config = Jaeger.Configuration.FromEnv(loggerFactory); var tracer = config.GetTracer(); GlobalTracer.Register(tracer); serviceCollection.AddSingleton(sp => GlobalTracer.Instance); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline public void Configure(IApplicationBuilder app, IHostingEnvironment env, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory) { //-------------------------------------------------------serilog 配置 AuthLogOptions authLogOptions = new AuthLogOptions() { LogPath = "D:\\LogFiles_TokenAuth",//Configuration[nameof(AuthLogOptions.LogPath)], PathFormat = "Auth_{Date}.log" }; var serilog = new LoggerConfiguration() .MinimumLevel.Debug() .Enrich.FromLogContext() .WriteTo.RollingFile(Path.Combine(authLogOptions.LogPath, authLogOptions.PathFormat), outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {Message}{NewLine}{Exception}"); AuthLogOptions.EnsurePreConditions(authLogOptions); loggerFactory.AddSerilog(serilog.CreateLogger()); // Ensure any buffered events are sent at shutdown 日志的生命周期 IApplicationLifetime appLifetime = (IApplicationLifetime)app.ApplicationServices.GetService(typeof(IApplicationLifetime)); if (appLifetime != null) { appLifetime.ApplicationStopped.Register(Serilog.Log.CloseAndFlush); } app.UseAuthLog(authLogOptions);//这个中间件用作记录请求中的过程日志 //---------------------------------------------------serilog 配置 //loggerFactory.AddConsole(Configuration.GetSection("Logging")); //loggerFactory.AddDebug(); app.UseMvc(); app.UseStaticFiles(); // Add JWT generation endpoint: var signingKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(secretKey)); var options = new TokenProviderOptions { Audience = "JyAudience", Issuer = "JyIssuer", Expiration = new TimeSpan(0, 30, 0), SigningCredentials = new SigningCredentials(signingKey, SecurityAlgorithms.HmacSha256), }; app.UseMiddleware <TokenProviderMiddleware>(Options.Create(options)); app.UseMvc(); //往zookeeper注册服务 TokenAuthRegister.registerTokenAuthHostPort(Configuration.GetSection("UrlConfig").GetValue <string>("ZooKeeperList")); }
public WebSocketServer(string location, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory = null) { Logger.AssignLoggerFactory(loggerFactory); var uri = new Uri(location); this.Port = uri.Port; this.Location = location; this._locationIP = ParseIPAddress(uri); this._scheme = uri.Scheme; var socket = new Socket(_locationIP.AddressFamily, SocketType.Stream, ProtocolType.IP); this.ListenerSocket = new SocketWrapper(socket); this.SupportedSubProtocols = new string[0]; }
void IStartup.Configure(IApplicationBuilder app) { this.m_Application = app; Microsoft.Extensions.Logging.ILoggerFactory loggerFactory = app.ApplicationServices. GetRequiredService <Microsoft.Extensions.Logging.ILoggerFactory>(); Microsoft.AspNetCore.Hosting.IHostingEnvironment env = app.ApplicationServices. GetRequiredService <Microsoft.AspNetCore.Hosting.IHostingEnvironment>(); Microsoft.AspNetCore.Http.IHttpContextAccessor httpContext = app.ApplicationServices. GetRequiredService <Microsoft.AspNetCore.Http.IHttpContextAccessor>(); this.Configure(app, env); }
public static Microsoft.Extensions.Logging.ILoggerFactory AddLog4Net(this Microsoft.Extensions.Logging.ILoggerFactory factory, string configuration = "log4net.config") { if (Path.IsPathRooted(configuration)) { var assembly = Assembly.GetEntryAssembly() ?? throw new InvalidOperationException("Не улаось определить сборку"); var dir = Path.GetDirectoryName(assembly.Location) ?? throw new InvalidOperationException("Не удалось определить папку со сборкой"); configuration = Path.Combine(dir, configuration); } factory.AddProvider(new Log4NetLoggerProvider(configuration)); return(factory); }
public ServiceLogicRoot( TokenValidationParameters tokenValidationParameters, ILoggerFactory loggerFactory) { var storageAdapter = new StorageAdapter(); var appLogicRoot = new AppLogicRoot( storageAdapter.UserTodosDao, new NewGuidBasedIdSequence()); var endpointsAdapter = new EndpointsAdapter( appLogicRoot.TodoCommandFactory, appLogicRoot.TodoCommandFactory, tokenValidationParameters, LoggingAdapter.CreateServiceSupport(loggerFactory)); _endpointsAdapter = endpointsAdapter; _storageAdapter = new StorageAdapter(); }
public void Configure(IApplicationBuilder app, IHostingEnvironment env, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory) { loggerFactory.AddSerilog(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Error"); } app.UseIdentityServer(); app.UseStaticFiles(); app.UseMvc(routes => { routes.MapRoute("default", "{controller=Account}/{action=SignIn}"); }); }
public LoggingFactory(Microsoft.Extensions.Logging.ILoggerFactory vNextFactory) { _vNextFactory = vNextFactory; }