locked
Trying to use TextWriterTraceListener in Batch Apps RRS feed

  • Question

  • I'm trying to use tracing in a batch apps service and I can't seem to get it to work.

    The code for my task processor looks like this:

    public class PCDSBatchCloudAppTaskProcessor : ParallelTaskProcessor
    {
        static PCDSBatchCloudAppTaskProcessor()
        {
            var textListener = new TextWriterTraceListener(Path.Combine(Environment.CurrentDirectory, "trace.log"));
            Trace.Listeners.Add(textListener);
            Trace.AutoFlush = true;
        }

    ....etc

    Later during RunTaskExternalProcess, my code ends up calling Trace.WriteLine for some of it's operations.

    I have a separate method to build out the TaskProcessResult that looks like this:

    public static TaskProcessResult BuildTaskProcessResult(TaskResults results, params string[] outputFiles)
    {
        TaskProcessResult taskProcessResult = new TaskProcessResult { Success = results.ExitCode == 0 ? TaskProcessSuccess.Succeeded : TaskProcessSuccess.RetryableFailure, ProcessorOutput = results.StandardOutput };
        TaskProcessResult result = taskProcessResult;
        var traceFileName = Path.Combine(Environment.CurrentDirectory, "trace.log");
        if (File.Exists(traceFileName))
        {
            result.ProcessorOutput = File.ReadAllText(traceFileName);
        }
        else
        {
            result.ProcessorOutput = "missing trace.log";
        }

    ....etc.

    Every time I run a job with this, i always get "missing trace.log" in the task output.

    Is there a way for me to use TextWriterTraceListener in my jobs? Am I doing something wrong?

    Thanks,

    Matt

    Wednesday, March 18, 2015 3:21 AM

Answers

  • Hi Matt,

    I believe the use of a TextWriterTraceListener is supported.

    Please try using base.LocalStoragePath in place of Environment.CurrentDirectory.

    I wouldn't make any assumption that the Environment.CurrentDirectory is a writeable directory. You could confirm that by trying to write a file.

    Hope this helps,
    Peter

    • Marked as answer by blueawning Thursday, March 19, 2015 3:02 PM
    Thursday, March 19, 2015 2:25 AM

All replies

  • Hi Matt,

    I believe the use of a TextWriterTraceListener is supported.

    Please try using base.LocalStoragePath in place of Environment.CurrentDirectory.

    I wouldn't make any assumption that the Environment.CurrentDirectory is a writeable directory. You could confirm that by trying to write a file.

    Hope this helps,
    Peter

    • Marked as answer by blueawning Thursday, March 19, 2015 3:02 PM
    Thursday, March 19, 2015 2:25 AM
  • I updated my code to use the LocalStorage path and it's writing out the trace file.

    I also found that I need to close the trace listener when I was trying to include the trace file as one of the output files of the job

    Thursday, March 19, 2015 3:02 PM
  • Hi Matt,

    Thanks for the feedback. Pleased that you were able to upload the trace and an output.

    Cheers,

    Peter

    Thursday, March 19, 2015 8:21 PM