我指的是这个link来记录从log4net到Azure表存储的异常。
现在,我需要在.net核心中的azure函数中执行相同的操作,但是由于azure函数中没有配置文件,因此无法在其中使用相同的功能。
感谢任何帮助以获取任何参考。
答案 0 :(得分:0)
现在我需要在.net核心中的azure函数中执行相同的操作,但是由于azure函数中没有配置文件,因此无法在其中使用相同的文件?
似乎您正在尝试读取通常从配置文件中读取的某些属性。是的,您也可以在Azure Function
中进行操作。文件名为local.settings.json
,您可以从此处读取所需的属性。请参见下面的示例:
local.settings.json:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"TableName": "YourTableName",
"AccountName": "YourAccountName",
"AccountKey": "YourAccountKey"
}
}
从local.settings.json
读取Azure功能上的属性:
public static class AzureFunctionApp2Arunraj414CaseForGetConfigProperty
{
[FunctionName("AzureFunctionApp2Arunraj414CaseForGetConfigProperty")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
//Read Request Body
var content = await new StreamReader(req.Body).ReadToEndAsync();
//Extract Request Body and Parse To Class
Users objUsers = JsonConvert.DeserializeObject<Users>(content);
//You Can Read Your Desired Value from local.settings.json file Like Below
var yourTableNameFromLocalSettingsJson = Environment.GetEnvironmentVariable("TableName");
var yourAccountNameFromLocalSettingsJson = Environment.GetEnvironmentVariable("AccountName");
var yourAccountKeyFromLocalSettingsJson = Environment.GetEnvironmentVariable("AccountKey");
//I am returning all the property I got from local.settings.json
var result = new OkObjectResult(yourTableNameFromLocalSettingsJson +" & "+ yourAccountNameFromLocalSettingsJson + " & " + yourAccountKeyFromLocalSettingsJson+ " From local.settings.json");
return result;
}
}
调试和测试:
请参见以下屏幕截图:
注意:您甚至可以将
local.settings.json
文件中的值之外的属性设置为单独的属性
如果您仍有任何问题,请随时分享。谢谢,祝您编程愉快!