本文整理汇总了C#中Microsoft.Framework.DependencyInjection.ServiceCollection.AddLogging方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceCollection.AddLogging方法的具体用法?C# ServiceCollection.AddLogging怎么用?C# ServiceCollection.AddLogging使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Framework.DependencyInjection.ServiceCollection
的用法示例。
在下文中一共展示了ServiceCollection.AddLogging方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConfigureServices
private IServiceProvider ConfigureServices()
{
var services = new ServiceCollection();
DbUtil.ConfigureDbServices<IdentityDbContext>(ConnectionString, services);
services.AddLogging();
services.AddIdentity<IdentityUser, IdentityRole>().AddEntityFrameworkStores<IdentityDbContext>();
return services.BuildServiceProvider();
}
示例2: CreateTestServices
public static IServiceCollection CreateTestServices()
{
var services = new ServiceCollection();
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddLogging();
services.AddIdentity<IdentityUser, IdentityRole>();
return services;
}
示例3: CheckThatLoggerWorksWithoutExceptions
public void CheckThatLoggerWorksWithoutExceptions()
{
ServiceCollection services = new ServiceCollection();
services.AddLogging();
IServiceProvider serviceProvider = services.BuildServiceProvider();
ILoggerFactory loggerFactory = (ILoggerFactory)serviceProvider.GetService(typeof(ILoggerFactory));
loggerFactory.MinimumLevel = LogLevel.Debug;
loggerFactory.AddLog4Net("Log4Net.config");
ILogger logger = loggerFactory.CreateLogger<Log4NetLoggerTest>();
logger.LogInformation("test log message");
}
示例4: SqliteMetadataModelProviderTest
public SqliteMetadataModelProviderTest()
{
_testStore = SqliteTestStore.CreateScratch();
var serviceCollection = new ServiceCollection();
serviceCollection.AddLogging();
new SqliteDesignTimeMetadataProviderFactory().AddMetadataProviderServices(serviceCollection);
serviceCollection.AddScoped(typeof(ILogger), sp => { return _logger = new TestLogger(); });
serviceCollection.AddScoped<IFileService, FileSystemFileService>();
_metadataModelProvider = serviceCollection
.BuildServiceProvider()
.GetService<IDatabaseMetadataModelProvider>() as SqliteMetadataModelProvider;
}
示例5: BuildServices
private IServiceProvider BuildServices()
{
var services = new ServiceCollection();
services.AddLogging();
services.AddTransient<Push>();
services.AddTransient<Pull>();
services.AddTransient<Request>();
services.AddTransient<Response>();
services.AddTransient<Publisher>();
services.AddTransient<Subscriber>();
return services.BuildServiceProvider();
}
示例6: SqliteMetadataModelProviderTest
public SqliteMetadataModelProviderTest()
{
_testStore = SqliteTestStore.CreateScratch();
var serviceCollection = new ServiceCollection();
serviceCollection.AddLogging();
new SqliteDesignTimeMetadataProviderFactory().AddMetadataProviderServices(serviceCollection);
serviceCollection.AddSingleton<IFileService, FileSystemFileService>();
var serviceProvider = serviceCollection
.BuildServiceProvider();
_logger = new TestLogger();
serviceProvider.GetService<ILoggerFactory>().AddProvider(new TestLoggerProvider(_logger));
_metadataModelProvider = serviceProvider
.GetService<IDatabaseMetadataModelProvider>() as SqliteMetadataModelProvider;
}
示例7: UseScriptConsole
public static void UseScriptConsole(this IApplicationBuilder app, IServiceCollection theServices)
{
var appS = app.ApplicationServices;
var scriptManager = new ScriptManager();
var services = new ServiceCollection();
services.Clear();
foreach (var s in theServices)
services.Insert(0, s);
services.AddInstance<ScriptManager>(scriptManager);
var fp = new DebugFileProvider(new EmbeddedFileProvider(typeof(ScriptConsoleBuilderExtensions).Assembly, "ScriptConsole"));
services
.AddMvc()
.AddControllersAsServices(new[] { typeof(ScriptConsoleController), typeof(HomeController) })
.AddRazorOptions(r => r.FileProvider = fp);
services.AddLogging();
var provider = services.BuildServiceProvider();
app.Map("/ScriptConsole", builder =>
{
var routeBuilder = new RouteBuilder()
{
DefaultHandler = new MvcRouteHandler(),
ServiceProvider = new ShadowedServiceProvider(provider, app.ApplicationServices)
};
routeBuilder.MapRoute("ScriptConsole", "{action}", new { controller = "ScriptConsole", action = "Index" });
routeBuilder.MapRoute("ScriptConsoleX", "{controller}/{action}", new { controller = "ScriptConsole", action = "Index" });
var route = routeBuilder.Build();
builder.Use(next =>
{
return async (context) =>
{
context.ApplicationServices = new ShadowedServiceProvider(provider, context.ApplicationServices);
context.RequestServices = new ShadowedServiceProvider(provider, context.RequestServices);
await route.RouteAsync(new RouteContext(context));
};
});
});
}
示例8: VerifyAccountControllerSignIn
public async Task VerifyAccountControllerSignIn(bool isPersistent)
{
var app = new ApplicationBuilder(CallContextServiceLocator.Locator.ServiceProvider);
app.UseCookieAuthentication();
var context = new Mock<HttpContext>();
var auth = new Mock<AuthenticationManager>();
context.Setup(c => c.Authentication).Returns(auth.Object).Verifiable();
auth.Setup(a => a.SignInAsync(new IdentityCookieOptions().ApplicationCookieAuthenticationScheme,
It.IsAny<ClaimsPrincipal>(),
It.IsAny<AuthenticationProperties>())).Returns(Task.FromResult(0)).Verifiable();
// REVIEW: is persistant mocking broken
//It.Is<AuthenticationProperties>(v => v.IsPersistent == isPersistent))).Returns(Task.FromResult(0)).Verifiable();
var contextAccessor = new Mock<IHttpContextAccessor>();
contextAccessor.Setup(a => a.HttpContext).Returns(context.Object);
var services = new ServiceCollection();
services.AddLogging();
services.AddInstance(contextAccessor.Object);
services.AddIdentity<TestUser, TestRole>();
services.AddSingleton<IUserStore<TestUser>, InMemoryUserStore<TestUser>>();
services.AddSingleton<IRoleStore<TestRole>, InMemoryRoleStore<TestRole>>();
app.ApplicationServices = services.BuildServiceProvider();
// Act
var user = new TestUser
{
UserName = "Yolo"
};
const string password = "[email protected]!";
var userManager = app.ApplicationServices.GetRequiredService<UserManager<TestUser>>();
var signInManager = app.ApplicationServices.GetRequiredService<SignInManager<TestUser>>();
IdentityResultAssert.IsSuccess(await userManager.CreateAsync(user, password));
var result = await signInManager.PasswordSignInAsync(user, password, isPersistent, false);
// Assert
Assert.True(result.Succeeded);
context.VerifyAll();
auth.VerifyAll();
contextAccessor.VerifyAll();
}
示例9: ManageControllerTest
public ManageControllerTest()
{
var services = new ServiceCollection();
services.AddEntityFramework()
.AddInMemoryDatabase()
.AddDbContext<MusicStoreContext>(options => options.UseInMemoryDatabase());
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<MusicStoreContext>();
services.AddLogging();
// IHttpContextAccessor is required for SignInManager, and UserManager
var context = new DefaultHttpContext();
context.SetFeature<IHttpAuthenticationFeature>(new HttpAuthenticationFeature() { Handler = new TestAuthHandler() });
services.AddInstance<IHttpContextAccessor>(
new HttpContextAccessor()
{
HttpContext = context,
});
_serviceProvider = services.BuildServiceProvider();
}
示例10: CreateContainer
public IServiceProvider CreateContainer(ShellSettings settings, ShellBlueprint blueprint)
{
ServiceCollection serviceCollection = new ServiceCollection();
serviceCollection.AddScoped<IOrchardShell, DefaultOrchardShell>();
serviceCollection.AddScoped<IRouteBuilder, DefaultShellRouteBuilder>();
serviceCollection.AddInstance(settings);
serviceCollection.AddInstance(blueprint.Descriptor);
serviceCollection.AddInstance(blueprint);
foreach (var dependency in blueprint.Dependencies
.Where(t => typeof (IModule).IsAssignableFrom(t.Type))) {
Logger.Debug("IModule Type: {0}", dependency.Type);
// TODO: Rewrite to get rid of reflection.
var instance = (IModule) Activator.CreateInstance(dependency.Type);
instance.Configure(serviceCollection);
}
var p = _serviceProvider.GetService<IOrchardLibraryManager>();
serviceCollection.AddInstance<IAssemblyProvider>(new DefaultAssemblyProviderTest(p, _serviceProvider, _serviceProvider.GetService<IAssemblyLoaderContainer>()));
foreach (var dependency in blueprint.Dependencies
.Where(t => !typeof(IModule).IsAssignableFrom(t.Type)))
{
foreach (var interfaceType in dependency.Type.GetInterfaces()
.Where(itf => typeof(IDependency).IsAssignableFrom(itf)))
{
Logger.Debug("Type: {0}, Interface Type: {1}", dependency.Type, interfaceType);
if (typeof(ISingletonDependency).IsAssignableFrom(interfaceType))
{
serviceCollection.AddSingleton(interfaceType, dependency.Type);
}
else if (typeof(IUnitOfWorkDependency).IsAssignableFrom(interfaceType))
{
serviceCollection.AddScoped(interfaceType, dependency.Type);
}
else if (typeof(ITransientDependency).IsAssignableFrom(interfaceType))
{
serviceCollection.AddTransient(interfaceType, dependency.Type);
}
else
{
serviceCollection.AddScoped(interfaceType, dependency.Type);
}
}
}
serviceCollection.AddLogging();
return new WrappingServiceProvider(_serviceProvider, serviceCollection);
}
示例11: CreateContainer
public IServiceProvider CreateContainer(ShellSettings settings, ShellBlueprint blueprint)
{
IServiceCollection serviceCollection = new ServiceCollection();
serviceCollection.AddLogging();
serviceCollection.AddInstance(settings);
serviceCollection.AddInstance(blueprint.Descriptor);
serviceCollection.AddInstance(blueprint);
foreach (var dependency in blueprint.Dependencies
.Where(x => x.Type.Name == "ShellStartup" ||
x.Type.Name == (settings.Name + "ShellStartup"))) {
_logger.LogDebug("Shell Startup: {0}", dependency.Type);
// TODO: Rewrite to get rid of reflection.
var instance = Activator.CreateInstance(dependency.Type);
var info = instance.GetType();
info.GetMethod("ConfigureServices").Invoke(instance, new[] { serviceCollection });
}
foreach (var dependency in blueprint.Dependencies
.Where(t => typeof (IModule).IsAssignableFrom(t.Type))) {
_logger.LogDebug("IModule Type: {0}", dependency.Type);
// TODO: Rewrite to get rid of reflection.
var instance = (IModule) Activator.CreateInstance(dependency.Type);
instance.Configure(serviceCollection);
}
foreach (var dependency in blueprint.Dependencies
.Where(t => !typeof(IModule).IsAssignableFrom(t.Type)))
{
foreach (var interfaceType in dependency.Type.GetInterfaces()
.Where(itf => typeof(IDependency).IsAssignableFrom(itf)))
{
_logger.LogDebug("Type: {0}, Interface Type: {1}", dependency.Type, interfaceType);
if (typeof(ISingletonDependency).IsAssignableFrom(interfaceType))
{
serviceCollection.AddSingleton(interfaceType, dependency.Type);
}
else if (typeof(IUnitOfWorkDependency).IsAssignableFrom(interfaceType))
{
serviceCollection.AddScoped(interfaceType, dependency.Type);
}
else if (typeof(ITransientDependency).IsAssignableFrom(interfaceType))
{
serviceCollection.AddTransient(interfaceType, dependency.Type);
}
else
{
serviceCollection.AddScoped(interfaceType, dependency.Type);
}
}
}
return new WrappingServiceProvider(_serviceProvider, serviceCollection);
}