本文整理汇总了C#中IServiceCollection.AddLogging方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceCollection.AddLogging方法的具体用法?C# IServiceCollection.AddLogging怎么用?C# IServiceCollection.AddLogging使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IServiceCollection
的用法示例。
在下文中一共展示了IServiceCollection.AddLogging方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConfigureServices
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddLogging();
services.AddTransient<TestRunner, TestRunner>();
return ServiceProvider = services.BuildServiceProvider();
}
示例2: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddLogging();
services.AddSingleton<FabricClient>();
services.AddSingleton<Resolver>();
services.AddMvc();
}
示例3: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
// dependency injection containers
public void ConfigureServices(IServiceCollection services)
{
// addjsonoptions -> dataobjecten naar camelCase ipv .net standaard wanneer men ze parsed, gemakkelijker voor js
services.AddMvc(/*config =>
{
//hier kan men forcen voor naar https versie van site te gaan, werkt momenteel niet, geen certificaten
config.Filters.Add(new RequireHttpsAttribute());
}*/)
.AddJsonOptions(opt =>
{
opt.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
});
services.AddLogging();
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<CatalogusContext>();
services.AddIdentity<Gebruiker, IdentityRole>(config =>
{
//todo requirements voor login
config.User.RequireUniqueEmail = true;
config.Password.RequiredLength = 8;
//route gebruikers naar loginpagina als ze afgeschermde url proberen te bereiken
config.Cookies.ApplicationCookie.LoginPath = "/Auth/Login";
//dit zorgt ervoor dat api calls niet naar loginpagina gereroute worden maar een echte error teruggeven aan de api caller
config.Cookies.ApplicationCookie.Events = new CookieAuthenticationEvents()
{
OnRedirectToLogin = ctx =>
{
if (ctx.Request.Path.StartsWithSegments("/api") && ctx.Response.StatusCode == (int)HttpStatusCode.OK)
{
//kijkt of er api call wordt gedaan en geeft dan correcte httpstatus terug, zodat de caller weet dat hij niet genoeg rechten heeft
ctx.Response.StatusCode = (int) HttpStatusCode.Unauthorized;
}
else
{
//Standaard gedrag
ctx.Response.Redirect(ctx.RedirectUri);
}
return Task.FromResult(0);
}
};
})
.AddEntityFrameworkStores<CatalogusContext>();
//Moet maar1x opgeroept worden, snellere garbage collect
services.AddTransient<CatalogusContextSeedData>();
services.AddScoped<ICatalogusRepository, CatalogusRepository>();
//eigen services toevoegen , bijv mail
//momenteel debugMail ingevoerd
services.AddScoped<IMailService, DebugMailService>();
}
示例4: ConfigureServices
// This method gets called by a runtime.
// Use this method to add services to the container
public void ConfigureServices(IServiceCollection services)
{
services.AddLogging();
services.Configure<MvcOptions>(options =>
{
var settings = new JsonSerializerSettings()
{
Formatting = Formatting.Indented,
NullValueHandling = NullValueHandling.Ignore,
ContractResolver = new CamelCaseExceptDictionaryKeysResolver()
};
options.InputFormatters.Clear();
options.OutputFormatters.Clear();
var inputFormatter = new JsonInputFormatter(settings);
var outputFormatter = new JsonOutputFormatter(settings);
options.InputFormatters.Insert(0, inputFormatter);
options.OutputFormatters.Insert(0, outputFormatter);
options.ModelBinders.Add(new UserPrincipleModelBinder());
options.Filters.Add(new AuthenticationFilterAttribute() { DataProvider = DataAccessControllerFactory.Provider });
options.Filters.Add(new HandleFinalErrorFilterAttribute());
});
services.AddSingleton<IControllerFactory, DataAccessControllerFactory>();
services.AddMvc();
}
示例5: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc()
.AddJsonOptions(
opt => { opt.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); });
services.AddLogging();
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<JuveDbContext>(options =>
options.UseSqlServer("Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=JuveV;Integrated Security=True"));
services.AddIdentity<ApplicationUser, IdentityRole>(s =>
{
s.Password.RequireDigit = false;
s.Password.RequireUppercase = false;
s.Password.RequiredLength = 3;
s.Password.RequireNonLetterOrDigit = false;
s.Password.RequireLowercase = false;
})
.AddEntityFrameworkStores<JuveDbContext>()
.AddDefaultTokenProviders();
RegisterClasses(services);
}
示例6: ConfigureServices
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
// Add Entity Framework services to the services container.
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<CenterContext>(options =>
options.UseSqlServer(Configuration["Database:ConnectionString"]));
services.AddCaching(); // 这两个必须同时添加,因为Session依赖于Caching
services.AddSession(x => x.IdleTimeout = TimeSpan.FromMinutes(20));
services.Configure<IdentityDbContextOptions>(options =>
{
options.DefaultAdminUserName = Configuration["DefaultAdminUsername"];
options.DefaultAdminPassword = Configuration["DefaultAdminPassword"];
});
services.AddIdentity<User, Role>(x =>
{
x.Password.RequireDigit = false;
x.Password.RequiredLength = 0;
x.Password.RequireLowercase = false;
x.Password.RequireNonLetterOrDigit = false;
x.Password.RequireUppercase = false;
})
.AddEntityFrameworkStores<CenterContext, long>()
.AddDefaultTokenProviders();
services.AddMvc();
services.AddLogging();
}
示例7: ConfigureServices
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc(config =>
{
#if !DEBUG
config.Filters.Add(new RequireHttpsAttribute());//redirect to https for entire site
#endif
})
.AddJsonOptions(op =>
{
op.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
}
);
services.AddIdentity<WorldUser, IdentityRole>(config =>
{
config.User.RequireUniqueEmail = true;
config.Password.RequiredLength = 8;
//path to redirect to when accessing a Authorized action
config.Cookies.ApplicationCookie.LoginPath = "/Auth/Login";
config.Cookies.ApplicationCookie.Events = new CookieAuthenticationEvents()
{
//redirect is called when unauth is made, this will stop the html being returned in a unauth call
OnRedirect = ctx =>
{
//if an api call is being made and the previous call is ok
if (ctx.Request.Path.StartsWithSegments("/api") &&
ctx.Response.StatusCode == (int)HttpStatusCode.OK)
{
ctx.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
}
else
{
ctx.Response.Redirect(ctx.RedirectUri);
}
return Task.FromResult(0);
}
};
})
.AddEntityFrameworkStores<WorldContext>();
services.AddLogging();
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<WorldContext>();
services.AddTransient<TheWorldContextSeedData>();
services.AddScoped<IWorldRepository, WorldRepository>();
services.AddScoped<IMailService, DebugMailService>();
services.AddScoped<CoordService>();
}
示例8: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services.AddOptions();
services.Configure<MessageConfiguration>(Configuration);
services.AddLogging();
services.AddScoped<ISecretNumber>(provider => new SecretNumber(Configuration));
}
示例9: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<AppSettings>(s =>
{
var appSettings = new AppSettings();
Configuration.GetSection("AppSettings").Bind(appSettings);
return appSettings;
});
services.AddSingleton<Client>(s =>
{
var appEnv = s.GetService<IApplicationEnvironment>();
var settings = s.GetService<AppSettings>();
var markdownCache = new SqliteMarkdownCache(
Path.Combine(
appEnv.ApplicationBasePath,
"releases-db.sqlite"));
return new Client(
settings.AccessToken,
markdownCache,
s.GetService<ILogger<Client>>(),
string.IsNullOrEmpty(settings.Company) ? Client.DefaultUserAgent : settings.Company
);
});
services.AddLogging();
// Add framework services.
services.AddMvc();
}
示例10: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
var builder = new ConfigurationBuilder()
.SetBasePath(this.appEnv.ApplicationBasePath)
.AddJsonFile("config.json")
.AddEnvironmentVariables();
var configRoot = builder.Build();
this.env.Initialize(this.appEnv.ApplicationBasePath, configRoot);
services.AddInstance(configRoot);
services.AddInstance(new Configuration(configRoot));
DatabaseConfiguration.ConfigureIdentity(services, this.env);
DatabaseConfiguration.ConfigureEntityFramework(services, configRoot, this.env, IsWindows);
this.AddMvcServiceSetup(services);
services.AddCaching();
services.AddSession();
services.AddLogging();
services.AddAntiforgery();
services.AddSingleton<IAntiforgeryTokenStore, AntiforgeryTokenStore>();
services.AddTransient<ISeedData, SeedData>();
services.AddScoped<ViewModelValidator>();
RepositoryConfiguration.ConfigureRepositories(services);
}
示例11: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddLogging();
// Note: why do we need to configure DBContext lke this? Can't we add scoped like below?
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<WorldContext>();
// Note: AddSingleton will share the object for the lifetime of the webserver
// AddScoped will share the object for the lifetime of the request
// AddTransient will give you a new object everytime
// AddInstance allows you create your own object and pass it in directly
services.AddTransient<WorldContextSeedData>();
services.AddScoped<IWorldRepository, WorldRepository>();
#if DEBUG
services.AddScoped<IMailService, DebugMailService>();
#else
// Add real mail service
#endif
}
示例12: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().AddJsonOptions(opt =>
opt.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver());
services.AddIdentity<WorldUser, IdentityRole>(
config =>
{
config.User.RequireUniqueEmail = true;
config.Password.RequiredLength = 5;
config.Cookies.ApplicationCookie.LoginPath = "/Auth/Login";
config.Cookies.ApplicationCookie.Events = new CookieAuthenticationEvents()
{
OnRedirectToLogin = ctx =>
{
if (ctx.Request.Path.StartsWithSegments("/api") &&
ctx.Response.StatusCode == (int) HttpStatusCode.OK)
{
ctx.Response.StatusCode = (int) HttpStatusCode.Unauthorized;
}else
ctx.Response.Redirect(ctx.RedirectUri);
return Task.FromResult(0);
}
};
})
.AddEntityFrameworkStores<WorldContext>();
services.AddLogging();
services.AddEntityFramework().AddSqlServer().AddDbContext<WorldContext>();
services.AddScoped<IMailService, DebugMailService>();
services.AddTransient<WorldContextSeedData>();
services.AddScoped<IWorldRepository, WorldRepository>();
services.AddScoped<CoorService>();
}
示例13: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddLogging();
services.AddScoped<IBundleService, BundleService>();
services.Configure<RazorViewEngineOptions>(opts =>
{
opts.ViewLocationExpanders.Add(_modularViewLocations);
});
services.AddEntityFramework()
.AddSqlite()
.AddDbContext<DjContext>();
/*
// Adds a pre-existing instance that will be referenced
IServiceCollection AddInstance<TService>(TService implementationInstance);
// Creates an instance once per request scope
IServiceCollection AddScoped<TService, TImplementation>();
// Creates a single instance that will be used each time the service is requested
IServiceCollection AddSingleton<TService>();
// Creates a new instance each time the service is requested
IServiceCollection AddTransient<TService>();
*/
}
示例14: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<GcseChineseDbContext>(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<GcseChineseDbContext>()
.AddDefaultTokenProviders();
services.AddMvc().AddJsonOptions(
opt=> opt.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver()
);
// Add application services.
services.AddTransient<IEmailSender, AuthMessageSender>();
services.AddTransient<ISmsSender, AuthMessageSender>();
// Add interfaces
services.AddTransient<GcseSeededData>();
services.AddScoped<IAssessmentRepository, AssessmentRepository>();
services.AddScoped<IExampaperRepository, ExampaperRepository>();
services.AddScoped<IThemeRepository, ThemeRepository>();
services.AddScoped<ITopicRepository, TopicRepository>();
services.AddLogging();
}
示例15: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services.AddHosting();
services.AddOptions();
services.AddLogging();
services.AddMvc();
// configuring services
// force JSON
// remove XML
services.Configure<Microsoft.AspNet.Mvc.MvcOptions>
(
options
=>
options
.OutputFormatters
.RemoveAll
(
formatter
=>
formatter.Instance
is
Microsoft.AspNet.Mvc.XmlDataContractSerializerOutputFormatter
)
);
return;
}