Gets the host log.
Namespace: AGI.Parallel.Client
Assembly: AGI.Parallel.Client (in AGI.Parallel.Client.dll) Version: 1.2.0.275 (1.2.0.275)

Syntax

C#
void GetHostLog(
        Guid agentId,
        TaskExecutionType taskExecuteType,
        int processId,
        Action<HostRequestLogResultMessage> onRequestHostLogReady
)
Visual Basic
Sub GetHostLog ( _
        agentId As Guid, _
        taskExecuteType As TaskExecutionType, _
        processId As Integer, _
        onRequestHostLogReady As Action(Of HostRequestLogResultMessage) _
)

Parameters

agentId
Type: System..::..Guid
The agent id.
taskExecuteType
Type: TaskExecutionType
Type of the task execute.
processId
Type: System..::..Int32
The process id.
onRequestHostLogReady
Type: System..::..Action<(Of <(<'HostRequestLogResultMessage>)>)>
The function called when log is ready.

Examples

  Copy imageCopy
using System;
using System.Threading;
using AGI.Parallel.Client;
using AGI.Parallel.Infrastructure;
using AGI.Parallel.Infrastructure.Logging;

namespace CodeSamples
{
    class Program
    {
        static void Main(string[] args)
        {
            TaskState ourTaskState = null;

            using (IJobScheduler scheduler = new ClusterJobScheduler("localhost"))
            {
                scheduler.Connect();

                Job job = scheduler.CreateJob();
                job.AddTask(new WriteSomeToLog());

                // You need to store the TaskState that you get from TaskSTateChanged
                job.TaskStateChanged += (notUsed, taskState) =>
                    {
                        if (taskState.State.ProcessId > 0)
                        {
                            ourTaskState = taskState.State;
                        }
                    };

                job.Submit();
                job.WaitUntilDone();

                HostRequestLogResultMessage logResult = null;
                ManualResetEvent logIsReady = new ManualResetEvent(false);

                // You have to check if your IJobScheduler interface supports IGetHostLog
                IGetHostLog canGetHostLog = scheduler as IGetHostLog;

                // Use the TaskState object you got above to call GetHostLog
                canGetHostLog.GetHostLog(
                    ourTaskState.AssignedWorker.Id,
                    TaskExecutionType.DotNet,
                    ourTaskState.ProcessId,
                    (hostLog) =>
                    {
                        logResult = hostLog;
                        logIsReady.Set();
                    });

                logIsReady.WaitOne();

                Console.WriteLine("Log Contents:");
                Console.WriteLine(logResult.LogContents);
            }

            /*
             * The output of the application should resemble:
             * Log Contents:
             * DEBUG 2013-02-25 10:51:17,554 - host received internal configuration: {} 
             * INFO  2013-02-25 10:51:20,795 - setting up Task Environment ...
             * DEBUG 2013-02-25 10:51:20,815 - adding assembly dependency SimpleExample, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
             * INFO  2013-02-25 10:51:20,890 - executing task #1 (SimpleTask)...
             * DEBUG 2013-02-25 10:51:21,004 - resolved assembly "SimpleExample, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" using task environment
             * DEBUG 2013-02-25 10:51:21,671 - resolved assembly "AGI.Parallel.Infrastructure, Version=0.0.0.0, Culture=neutral, PublicKeyToken=46f7a65aaf1b26a0" using already loaded assembly
             * DEBUG 2013-02-25 10:51:22,039 - starting cancel timer, effective cancel time is 30000ms
             * INFO  2013-02-25 10:51:22,041 - tearing down Task Environment...
             */
        }

        [Serializable]
        internal class WriteSomeToLog : Task
        {
            public override void Execute()
            {
                ILog logger = this.GetProperty<ILog>(TaskProperties.Logger);
                logger.Error("My text");
                logger.Fatal("should appear");
                logger.Fatal("in the file");
            }
        }
    }
}

See Also