- Azure Serverless Computing Cookbook
- Praveen Kumar Sreeram
- 158字
- 2021-06-10 18:56:00
Customizing the log file name using IBinder interface
Perform the following steps:
- Navigate to the run.csx file of the SendNotifications function.
- Remove the TextWriter object and replace it with the variable binder of the IBinder type. The following is the new signature of the Run method with the changes highlighted:
#r "SendGrid"
#r "Newtonsoft.Json"
#r "Microsoft.Azure.WebJobs.Extensions.Storage"
using System;
using SendGrid.Helpers.Mail;
using Newtonsoft.Json;
using Microsoft.Azure.WebJobs.Extensions.Storage;
public static void Run(string myQueueItem,
out SendGridMessage message,
IBinder binder,
ILogger log)
- We have removed the TextWriter object, and the outputBlob.WriteLine(emailContent); function will no longer work. Let's replace it with the following piece of code:
using (var emailLogBloboutput = binder.Bind<TextWriter>(new
BlobAttribute($"userregistrationemaillogs/
{objInsertedUser.RowKey}.log")))
{
emailLogBloboutput.WriteLine(emailContent);
}
- Let's run a test using the same request payload that we used in the previous recipes.
- You can see the email log file that is created using the RowKey of the new record stored in the Azure Table storage, as shown in the following screenshot: