我们已经到了2021年的一半了,我发现的所有WebJob答案都很古老。也许我错过了一个新的皱纹
这张来自我的Microsoft Azure Storage的图片说明了一切:
在我的machnine上,我使用这个appsettings.Development.json
文件--允许我的dotnet控制台与我的Azurite存储实例对话(Azurite正在从我的本地码头上运行)
{
"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();
})
..。我已将其保存到which的配置页面中:
成功地检测到并调用了我的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存储容器。
我遗漏了什么?
哦..。如果你一定要知道..。这些是我的裸体:
更新:
添加:我的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
发布于 2021-07-14 18:39:30
我可能遇到了很多问题,但是,我终于征服了。以下是我为解决我的困境所做的事情:
1.)我需要将AzureWebJobsStorage
键值放入我的Application Settings
中(也许以前的webjobs迭代会从Connection Strings
获得它--但现在不会了)
2.)我使用的是一些可能在#1上失败的5.0.0 beta
NuGet包,所以当我将它们滚回原处时。(特别是Microsoft.Azure.WebJobs.Extensions.Storage --我将其回滚到3.x.x -当我开始获取日志中显示的TLS版本错误时。4.0.4是稳定和快乐的)
下面是我当前的NuGet状态:
https://stackoverflow.com/questions/68369653
复制相似问题