我的Program
课看起来像这样
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args)
.Build()
.Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((webHostingBuilder, configBuilder) =>
{
configBuilder.SetBasePath(webHostingBuilder.HostingEnvironment.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{webHostingBuilder.HostingEnvironment.EnvironmentName}.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables();
})
.ConfigureLogging((webHostingBuilder, logging) =>
{
logging.ClearProviders();
logging.AddConsole();
logging.AddDebug();
logging.AddApplicationInsights(
webHostingBuilder.Configuration.GetValue<string>("Logging:ApplicationInsights:InstrumentationKey"));
})
.UseStartup<Startup>();
}
和我Startup
的ConfigureServices
services.AddApplicationInsightsTelemetry(configuration["Logging:ApplicationInsights:InstrumentationKey"]);
这是我的控制器类:
public class AccountController : BaseController
{
private ILogger _logger;
public AccountController(ILogger<AccountController> logger)
{ ... }
[HttpGet]
public async Task<IActionResult> Login(string returnUrl)
{
_logger.LogError("SuperError");
}
}
为了保存日志,我还需要配置其他什么吗?在做我的例子时,我在这里看不到任何东西