Azure Webjob TextWriter logger being disposed in the middle of my method

Brass Contributor

Hi,

I am using the following code in the web job (Microsoft.Azure.WebJobs 1.1.2)

that listens for events ItemAdded on sharepont lists. Occassionlly it is throwing the error- where it says TextWriter logger object is getting disposed.

 Does the higher versions of Microsoft.Azue.Webjobs fix this issue?

public class Functions

{

// This function will get triggered/executed when a new message is written

// on an Azure Queue called queue.

public static async Task ProcessQueueMessage([QueueTrigger("%" + PnPPartnerPackSettings.ListEventsWebJobQueueName + "%")] ListEventsJobInformation eventsJob, TextWriter log)

{

var logger = new TextWriterLogger(log);

Log.Logger = logger;

var config = (LogConfigurationTracingSection)System.Configuration.ConfigurationManager.GetSection("pnp/tracing");

Log.LogLevel = config?.LogLevel ?? LogLevel.Debug;

var job = SharePointEventsJobHelper.GetListEventsJob(eventsJob.ListTitle, eventsJob);

Log.Info(Constants.LOGGING_SOURCE, $"Found Job: List: {job.ListTitle}, SiteUrl: {job.SiteUrl}, ItemId: {job.ListItemId}");

// Get a reference to the Provisioning Job

if (PnPPartnerPackSettings.ContinousJobHandlers.ContainsKey(job.GetType()))

{

await PnPPartnerPackSettings.ContinousJobHandlers[job.GetType()].RunSharePointEventsJob(job);

}

Log.Info(Constants.LOGGING_SOURCE, "Completed Job execution");

}

}

 

 

Error:

Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: Functions.ProcessQueueMessage ---> System.ObjectDisposedException: Cannot write to a closed TextWriter. at System.IO.__Error.WriterClosed() at System.IO.StringWriter.Write(Char[] buffer, Int32 index, Int32 count) at System.IO.TextWriter.WriteLine(String value) at System.IO.TextWriter.SyncTextWriter.WriteLine(String value) at Microsoft.Azure.WebJobs.Host.CompositeTraceWriter.InvokeTextWriter(TraceEvent traceEvent) at Microsoft.Azure.WebJobs.Host.CompositeTraceWriter.Trace(TraceEvent traceEvent) at Microsoft.Azure.WebJobs.Host.Bindings.TextWriterTraceAdapter.Write(Char value) at System.IO.TextWriter.Write(Char[] buffer, Int32 index, Int32 count) at System.IO.TextWriter.WriteLine(String value) at XYZ.Provisioning.Common.Utilities.TextWriterLogger.Info(LogEntry entry) at OfficeDevPnP.Core.Diagnostics.Log.Info(String source, String message, Object[] args) at ListsWebJob.Functions.<ProcessQueueMessage>d__0.MoveNext() in ListsWebJob\Functions.cs:line 34 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`1.<InvokeAsync>d__0.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.<ExecuteWithWatchersAsync>d__31.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.<ExecuteWithLoggingAsync>d__2c.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.<ExecuteWithLoggingAsync>d__13.MoveNext() --- End of inner exception stack trace --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.<ExecuteWithLoggingAsync>d__13.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.<TryExecuteAsync>d__1.MoveNext()

 

0 Replies