NET 5.0 WebJob 只想写入我的本地 Blob 存储
Posted
技术标签:
【中文标题】NET 5.0 WebJob 只想写入我的本地 Blob 存储【英文标题】:NET 5.0 WebJob only wants to write to my local Blob storage 【发布时间】:2021-09-22 22:27:18 【问题描述】:2021 年已过半,我找到的所有 WebJob 答案都已经过时了。也许我缺少新的皱纹
这张来自我的 Microsoft Azure 存储资源管理器的图片说明了一切:
在我的机器上,我使用这个 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();
)
... 我已将其保存到我的 Web 应用服务的配置页面中:
我的 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
【问题讨论】:
AzureWebJobsStorage
是否设置为在生产中有效的东西?
@DavidG - 我相信是因为其他 webjob 基础设施-ish 容器在那里,如 azure-jobs-host-archive
、azure-jobs-host-output
、azure-webjobs-dashboard
和 azure-webjobs-host
所以,我相信其中一些已被使用支持单例锁等。我认为其他人可能会驱动仪表板日志记录。其中一些可能是剩余的,因为我上周之前的尝试是 WebJob 1.x 样式代码
@DavidG - 我创建了一个控制台应用程序based off this quickstart guide 并在那里使用了我的连接字符串,成功连接到我的tsllogging
存储。我创建的快速启动应用程序能够创建一个新容器并将 Blob 上传到其中。
【参考方案1】:
我可能遇到了多个问题,但是,我终于战胜了。 以下是我为解决问题所做的事情:
1.) 我需要将 AzureWebJobsStorage
键值放入我的 Application Settings
(也许以前的 webjobs 迭代会从 Connection Strings
获得它 - 但不再)
2.) 我正在使用一些 5.0.0 beta
NuGet 包,这些包可能在 #1 上失败了,所以当我将它们滚回来时。 (尤其是 Microsoft.Azure.WebJobs.Extensions.Storage - 我回滚到 3.x.x - 这是我开始在日志中显示 TLS 版本错误的时候。4.0.4 稳定且快乐)
这是我当前的 NuGet 状态:
【讨论】:
以上是关于NET 5.0 WebJob 只想写入我的本地 Blob 存储的主要内容,如果未能解决你的问题,请参考以下文章
如何在没有“始终开启”的情况下保持 Azure WebJob 运行
Azure Webjob TextWriter 记录器被放置在我的方法中间
适用于 .NET Core Azure WebJob 的 Application Insights
Azure WebJob“无法创建 SSL/TLS 安全通道”