2021 年已过半,我找到的所有 WebJob 答案都已经过时了。也许我缺少新的皱纹
这张来自我的 Microsoft Azure Storage Explorer 的图片说明了一切:
在我的机器上,我使用这个appsettings.Development.json
文件——允许我的 dotnet 控制台与我的 Azurite 存储实例通信(Azurite 从我的本地 Docker 运行)
{
"ConnectionStrings": {
"AzureWebJobsDashboard": "UseDevelopmentStorage=true",
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"ContosoData": "Initial Catalog=Contoso;Integrated Security=True;Encrypt=False;Data Source=(localdb)\\MSSQLLocalDB;"
}
}
在生产中,这些Program.cs
行将用我的“真实”连接字符串覆盖上面的内容......
.ConfigureAppConfiguration((hostingContext, conf) =>
{
var env = hostingContext.HostingEnvironment;
_configuration = conf
.SetBasePath(env.ContentRootPath)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
})
我的 Functions.cs 中的奇异方法被成功检测并调用 - 我正在使用此输出属性写入 Blob 存储
public class Functions
{
[Singleton]
public async static Task CopyDates(
[TimerTrigger("0 */5 * * * *", RunOnStartup = true)] TimerInfo myTimer,
[Blob("tsl-updater-logs/log.txt", FileAccess.Write)] TextWriter logger)
{
logger.WriteLine($"C# Timer trigger function executed at: {DateTime.Now}");
}
}
因为该功能被RunOnStartup = true
我的仪表板标记,所以很快就会显示该作业是Started
或Running
在我发布作业之后 - 但我从未看到 log.txt 文件被写入我的 Blob 存储容器
我错过了什么?
哦..如果你必须知道..这些是我的nugets:
更新:
添加:我的 Program.cs 的完整来源
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.EntityFrameworkCore;
using Microsoft.Azure.WebJobs.Host;
class Program
{
public static IConfiguration _configuration;
public static IServiceCollection _services;
static async Task Main(string[] args)
{
var builder = new HostBuilder();
builder
//.UseEnvironment("Development")
.ConfigureWebJobs(b =>
{
b.AddAzureStorageCoreServices();
b.AddAzureStorageBlobs();
b.AddTimers();
//b.AddDashboardLogging();
})
.ConfigureAppConfiguration((hostingContext, conf) =>
{
var env = hostingContext.HostingEnvironment;
_configuration = conf
.SetBasePath(env.ContentRootPath)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
})
.ConfigureLogging((context, b) =>
{
b.SetMinimumLevel(LogLevel.Information);
b.AddConsole();
})
.ConfigureServices(svc =>
{
svc.AddDbContext<Models.DataWareHouseCtx>(opt =>
opt.UseSqlServer(_configuration.GetConnectionString("DataWareHouse"))
.EnableSensitiveDataLogging(true)
.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking));
svc.AddDbContext<Models.TslDataContext>(opt =>
opt.UseSqlServer(_configuration.GetConnectionString("ThingStatusLocation"))
.EnableSensitiveDataLogging(true)
.UseQueryTrackingBehavior(QueryTrackingBehavior.TrackAll));
_services = svc;
});
//.UseConsoleLifetime();
var host = builder.Build();
using (host)
{
await host.RunAsync();
}
}
}
更新 2:
日志仪表板的输出
[07/13/2021 20:53:10 > ef3fc6: SYS INFO] Status changed to Stopped
[07/13/2021 21:24:12 > ef3fc6: SYS INFO] Detected WebJob file/s were updated, refreshing WebJob
[07/13/2021 21:24:12 > ef3fc6: SYS INFO] Status changed to Starting
[07/13/2021 21:24:12 > ef3fc6: SYS INFO] WebJob singleton setting is False
[07/13/2021 21:24:13 > ef3fc6: SYS INFO] Run script 'run.cmd' with script host - 'WindowsScriptHost'
[07/13/2021 21:24:13 > ef3fc6: SYS INFO] Status changed to Running
[07/13/2021 21:24:13 > ef3fc6: INFO]
[07/13/2021 21:24:13 > ef3fc6: INFO] D:\local\Temp\jobs\continuous\My.WebJob.Updater\s02hk5ti.50s>dotnet My.WebJob.Updater.dll
[07/13/2021 21:24:14 > ef3fc6: INFO] info: Microsoft.Azure.WebJobs.Extensions.Storage.Blobs.Config.BlobsExtensionConfigProvider[0]
[07/13/2021 21:24:14 > ef3fc6: INFO] registered http endpoint =
[07/13/2021 21:24:14 > ef3fc6: INFO] info: Microsoft.Azure.WebJobs.Hosting.OptionsLoggingService[0]
[07/13/2021 21:24:14 > ef3fc6: INFO] LoggerFilterOptions
[07/13/2021 21:24:14 > ef3fc6: INFO] {
[07/13/2021 21:24:14 > ef3fc6: INFO] "MinLevel": "Information",
[07/13/2021 21:24:14 > ef3fc6: INFO] "Rules": []
[07/13/2021 21:24:14 > ef3fc6: INFO] }
[07/13/2021 21:24:14 > ef3fc6: INFO] info: Microsoft.Azure.WebJobs.Hosting.OptionsLoggingService[0]
[07/13/2021 21:24:14 > ef3fc6: INFO] FunctionResultAggregatorOptions
[07/13/2021 21:24:14 > ef3fc6: INFO] {
[07/13/2021 21:24:14 > ef3fc6: INFO] "BatchSize": 1000,
[07/13/2021 21:24:14 > ef3fc6: INFO] "FlushTimeout": "00:00:30",
[07/13/2021 21:24:14 > ef3fc6: INFO] "IsEnabled": true
[07/13/2021 21:24:14 > ef3fc6: INFO] }
[07/13/2021 21:24:14 > ef3fc6: INFO] info: Microsoft.Azure.WebJobs.Hosting.OptionsLoggingService[0]
[07/13/2021 21:24:14 > ef3fc6: INFO] QueuesOptions
[07/13/2021 21:24:15 > ef3fc6: INFO] {
[07/13/2021 21:24:15 > ef3fc6: INFO] "BatchSize": 16,
[07/13/2021 21:24:15 > ef3fc6: INFO] "NewBatchThreshold": 16,
[07/13/2021 21:24:15 > ef3fc6: INFO] "MaxPollingInterval": "00:01:00",
[07/13/2021 21:24:15 > ef3fc6: INFO] "MaxDequeueCount": 5,
[07/13/2021 21:24:15 > ef3fc6: INFO] "VisibilityTimeout": "00:00:00",
[07/13/2021 21:24:15 > ef3fc6: INFO] "MessageEncoding": "Base64"
[07/13/2021 21:24:15 > ef3fc6: INFO] }
[07/13/2021 21:24:15 > ef3fc6: INFO] info: Microsoft.Azure.WebJobs.Hosting.OptionsLoggingService[0]
[07/13/2021 21:24:15 > ef3fc6: INFO] SingletonOptions
[07/13/2021 21:24:15 > ef3fc6: INFO] {
[07/13/2021 21:24:15 > ef3fc6: INFO] "LockPeriod": "00:00:15",
[07/13/2021 21:24:15 > ef3fc6: INFO] "ListenerLockPeriod": "00:01:00",
[07/13/2021 21:24:15 > ef3fc6: INFO] "LockAcquisitionTimeout": "10675199.02:48:05.4775807",
[07/13/2021 21:24:15 > ef3fc6: INFO] "LockAcquisitionPollingInterval": "00:00:05",
[07/13/2021 21:24:15 > ef3fc6: INFO] "ListenerLockRecoveryPollingInterval": "00:01:00"
[07/13/2021 21:24:15 > ef3fc6: INFO] }
[07/13/2021 21:24:15 > ef3fc6: INFO] info: Microsoft.Azure.WebJobs.Hosting.OptionsLoggingService[0]
[07/13/2021 21:24:15 > ef3fc6: INFO] BlobsOptions
[07/13/2021 21:24:15 > ef3fc6: INFO] {
[07/13/2021 21:24:15 > ef3fc6: INFO] "MaxDegreeOfParallelism": 16
[07/13/2021 21:24:15 > ef3fc6: INFO] }
[07/13/2021 21:24:15 > ef3fc6: INFO] info: Microsoft.Azure.WebJobs.Hosting.JobHostService[0]
[07/13/2021 21:24:15 > ef3fc6: INFO] Starting JobHost
[07/13/2021 21:24:15 > ef3fc6: INFO] info: Host.Startup[0]
[07/13/2021 21:24:15 > ef3fc6: INFO] Found the following functions:
[07/13/2021 21:24:15 > ef3fc6: INFO] Ross.WebJob.Tsl.Updater.Functions.CopyDates
[07/13/2021 21:24:15 > ef3fc6: INFO]
[07/13/2021 21:24:15 > ef3fc6: INFO] info: Host.Startup[0]
[07/13/2021 21:24:15 > ef3fc6: INFO] Job host started
[07/13/2021 21:24:15 > ef3fc6: INFO] Application started. Press Ctrl+C to shut down.
[07/13/2021 21:24:15 > ef3fc6: INFO] Hosting environment: Production
[07/13/2021 21:24:15 > ef3fc6: INFO] Content root path: D:\local\Temp\jobs\continuous\My.WebJob.Updater\s02hk5ti.50s\
[07/13/2021 21:34:22 > ef3fc6: SYS INFO] Detected WebJob file/s were updated, refreshing WebJob
[07/13/2021 21:34:22 > ef3fc6: SYS INFO] Status changed to Stopping
[07/13/2021 21:34:27 > ef3fc6: ERR ] Thread was being aborted.
[07/13/2021 21:34:27 > ef3fc6: SYS INFO] WebJob process was aborted
[07/13/2021 21:34:27 > ef3fc6: SYS INFO] Status changed to Stopped
[07/13/2021 21:34:28 > ef3fc6: SYS INFO] Status changed to Starting
[07/13/2021 21:34:28 > ef3fc6: SYS INFO] Run script 'run.cmd' with script host - 'WindowsScriptHost'
[07/13/2021 21:34:28 > ef3fc6: SYS INFO] Status changed to Running
[07/13/2021 21:34:28 > ef3fc6: INFO]
[07/13/2021 21:34:28 > ef3fc6: INFO] D:\local\Temp\jobs\continuous\My.WebJob.Tsl.Updater\s02hk5ti.50s>dotnet Ross.WebJob.Tsl.Updater.dll
[07/13/2021 21:34:29 > ef3fc6: INFO] info: Microsoft.Azure.WebJobs.Extensions.Storage.Blobs.Config.BlobsExtensionConfigProvider[0]
[07/13/2021 21:34:29 > ef3fc6: INFO] registered http endpoint =
[07/13/2021 21:34:29 > ef3fc6: INFO] info: Microsoft.Azure.WebJobs.Hosting.OptionsLoggingService[0]
[07/13/2021 21:34:29 > ef3fc6: INFO] LoggerFilterOptions
[07/13/2021 21:34:29 > ef3fc6: INFO] {
[07/13/2021 21:34:29 > ef3fc6: INFO] "MinLevel": "Information",
[07/13/2021 21:34:29 > ef3fc6: INFO] "Rules": []
[07/13/2021 21:34:29 > ef3fc6: INFO] }
[07/13/2021 21:34:29 > ef3fc6: INFO] info: Microsoft.Azure.WebJobs.Hosting.OptionsLoggingService[0]
[07/13/2021 21:34:29 > ef3fc6: INFO] FunctionResultAggregatorOptions
[07/13/2021 21:34:29 > ef3fc6: INFO] {
[07/13/2021 21:34:29 > ef3fc6: INFO] "BatchSize": 1000,
[07/13/2021 21:34:29 > ef3fc6: INFO] "FlushTimeout": "00:00:30",
[07/13/2021 21:34:29 > ef3fc6: INFO] "IsEnabled": true
[07/13/2021 21:34:29 > ef3fc6: INFO] }
[07/13/2021 21:34:29 > ef3fc6: INFO] info: Microsoft.Azure.WebJobs.Hosting.OptionsLoggingService[0]
[07/13/2021 21:34:29 > ef3fc6: INFO] QueuesOptions
[07/13/2021 21:34:29 > ef3fc6: INFO] {
[07/13/2021 21:34:29 > ef3fc6: INFO] "BatchSize": 16,
[07/13/2021 21:34:29 > ef3fc6: INFO] "NewBatchThreshold": 16,
[07/13/2021 21:34:29 > ef3fc6: INFO] "MaxPollingInterval": "00:01:00",
[07/13/2021 21:34:29 > ef3fc6: INFO] "MaxDequeueCount": 5,
[07/13/2021 21:34:29 > ef3fc6: INFO] "VisibilityTimeout": "00:00:00",
[07/13/2021 21:34:29 > ef3fc6: INFO] "MessageEncoding": "Base64"
[07/13/2021 21:34:29 > ef3fc6: INFO] }
[07/13/2021 21:34:29 > ef3fc6: INFO] info: Microsoft.Azure.WebJobs.Hosting.OptionsLoggingService[0]
[07/13/2021 21:34:29 > ef3fc6: INFO] SingletonOptions
[07/13/2021 21:34:29 > ef3fc6: INFO] {
[07/13/2021 21:34:29 > ef3fc6: INFO] "LockPeriod": "00:00:15",
[07/13/2021 21:34:29 > ef3fc6: INFO] "ListenerLockPeriod": "00:01:00",
[07/13/2021 21:34:29 > ef3fc6: INFO] "LockAcquisitionTimeout": "10675199.02:48:05.4775807",
[07/13/2021 21:34:29 > ef3fc6: INFO] "LockAcquisitionPollingInterval": "00:00:05",
[07/13/2021 21:34:29 > ef3fc6: INFO] "ListenerLockRecoveryPollingInterval": "00:01:00"
[07/13/2021 21:34:29 > ef3fc6: INFO] }
[07/13/2021 21:34:29 > ef3fc6: INFO] info: Microsoft.Azure.WebJobs.Hosting.OptionsLoggingService[0]
[07/13/2021 21:34:29 > ef3fc6: INFO] BlobsOptions
[07/13/2021 21:34:29 > ef3fc6: INFO] {
[07/13/2021 21:34:29 > ef3fc6: INFO] "MaxDegreeOfParallelism": 16
[07/13/2021 21:34:29 > ef3fc6: INFO] }
[07/13/2021 21:34:29 > ef3fc6: INFO] info: Microsoft.Azure.WebJobs.Hosting.JobHostService[0]
[07/13/2021 21:34:29 > ef3fc6: INFO] Starting JobHost
[07/13/2021 21:34:29 > ef3fc6: INFO] info: Host.Startup[0]
[07/13/2021 21:34:29 > ef3fc6: INFO] Found the following functions:
[07/13/2021 21:34:29 > ef3fc6: INFO] My.WebJob.Updater.Functions.CopyDates
[07/13/2021 21:34:29 > ef3fc6: INFO]
[07/13/2021 21:34:30 > ef3fc6: INFO] info: Host.Startup[0]
[07/13/2021 21:34:30 > ef3fc6: INFO] Job host started
[07/13/2021 21:34:30 > ef3fc6: INFO] Application started. Press Ctrl+C to shut down.
[07/13/2021 21:34:30 > ef3fc6: INFO] Hosting environment: Production
[07/13/2021 21:34:30 > ef3fc6: INFO] Content root path: D:\local\Temp\jobs\continuous\My.WebJob.Updater\s02hk5ti.50s\
[07/13/2021 22:34:28 > ef3fc6: SYS INFO] WebJob is still running
[07/14/2021 10:34:28 > ef3fc6: SYS INFO] WebJob is still running
更新 3:终于找到了一些东西 - 不支持 TLS 版本
当我选择查看流式日志时,来自 VS 中的输出窗格的片段
Application:Microsoft.WindowsAzure.Storage.StorageException: The remote server returned an error: (400) Bad Request. ---> System.Net.WebException: The remote server returned an error: (400) Bad Request.
Application: at System.Net.HttpWebRequest.GetResponse()
Application: at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext)
Application: --- End of inner exception stack trace ---
Application: at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext)
Application: at Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.DownloadBlockList(BlockListingFilter blockListingFilter, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext)
Application: at Microsoft.WindowsAzure.WebSites.Diagnostics.AzureBlobTraceListener.AppendStreamToBlob(Stream stream)
Application: at Microsoft.WindowsAzure.WebSites.Diagnostics.AzureBlobTraceListener.ConsumeBuffer()
Application:Request Information
Application:RequestID:6bbeae68-701e-009c-0ad8-787fc9000000
Application:RequestDate:Wed, 14 Jul 2021 17:46:01 GMT
Application:StatusMessage:The TLS version of the connection is not permitted on this storage account.
Application:ErrorCode:TlsVersionNotPermitted