Asp.net core 如何从azure function app将文件发送到azure存储
我正在使用azure函数应用程序(服务总线),每当excel文件上传到UI时,它都会触发。 无论出于何种原因,如果excel文件无法上载,则会抛出异常消息。 我想将该异常消息存储到文本文件中,并将该文本文件存储到存储帐户中。 Plz建议我如何将该文件从我的函数应用程序存储到stotage帐户中 异常代码如下所示:Asp.net core 如何从azure function app将文件发送到azure存储,asp.net-core,azure-functions,azure-storage,azure-storage-blobs,azure-table-storage,Asp.net Core,Azure Functions,Azure Storage,Azure Storage Blobs,Azure Table Storage,我正在使用azure函数应用程序(服务总线),每当excel文件上传到UI时,它都会触发。 无论出于何种原因,如果excel文件无法上载,则会抛出异常消息。 我想将该异常消息存储到文本文件中,并将该文本文件存储到存储帐户中。 Plz建议我如何将该文件从我的函数应用程序存储到stotage帐户中 异常代码如下所示: catch (Exception ex) { logger.LogInformation($"Exception: {ex.Messa
catch (Exception ex)
{
logger.LogInformation($"Exception: {ex.Message}, {ex.StackTrace}");
return "Failure";
}
也许您可以尝试使用以下代码:
catch (Exception ex)
{
log.LogInformation($"Exception: {ex.Message}, {ex.StackTrace}");
string connectionString = "";
BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);
string containerName = "";
// Create a local file in the ./data/ directory for uploading and downloading
string localPath = "./data/";
string fileName = "exception" + Guid.NewGuid().ToString() + ".txt";
string localFilePath = Path.Combine(localPath, fileName);
// Write text to the file
await File.WriteAllTextAsync(localFilePath, $"Exception: {ex.Message}, {ex.StackTrace}");
BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(containerName);
// Get a reference to a blob
BlobClient blobClient = containerClient.GetBlobClient(fileName);
// Open the file and upload its data
using FileStream uploadFileStream = File.OpenRead(localFilePath);
await blobClient.UploadAsync(uploadFileStream, true);
uploadFileStream.Close();
return "Failure";
}
请参考这个