我有 azure webjob sdk (v3.0.3) 应用程序,已配置为使用 serilog 进行日志记录。当我在系统中本地运行该应用程序时,该日志似乎有效。下面是配置:
static void Main(string[] args)
{
try
{
var builder = new HostBuilder()
.ConfigureAppConfiguration(SetupConfiguration)
.ConfigureLogging(SetupLogging)
.ConfigureServices(SetupServices)
.ConfigureWebJobs(webJobConfiguration =>
{
webJobConfiguration.AddTimers();
webJobConfiguration.AddAzureStorageCoreServices(); //this is to store logs in azure storage
})
.UseSerilog()
.Build();
builder.Run();
}
}
Run Code Online (Sandbox Code Playgroud)
设置配置的代码如下:
private static void SetupConfiguration(HostBuilderContext hostingContext, IConfigurationBuilder builder)
{
var env = hostingContext.HostingEnvironment;
_configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: false, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
}
Run Code Online (Sandbox Code Playgroud)
设置服务的代码:
private static void SetupServices(HostBuilderContext hostingContext, IServiceCollection …
Run Code Online (Sandbox Code Playgroud) logging azure serilog azure-webjobssdk azure-webjobs-continuous