Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net core 如何从azure function app将文件发送到azure存储_Asp.net Core_Azure Functions_Azure Storage_Azure Storage Blobs_Azure Table Storage - Fatal编程技术网

Asp.net core 如何从azure function app将文件发送到azure存储

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

我正在使用azure函数应用程序(服务总线),每当excel文件上传到UI时,它都会触发。 无论出于何种原因,如果excel文件无法上载,则会抛出异常消息。 我想将该异常消息存储到文本文件中,并将该文本文件存储到存储帐户中。 Plz建议我如何将该文件从我的函数应用程序存储到stotage帐户中

异常代码如下所示:

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";
            }
请参考这个