Log messages in task |
You want to write task messages to a persistent log file.
Get the reference to the ILog interface by calling GetProperty and passing in TaskPropertiesLogger.
ILog logger = this.GetProperty<ILog>(TaskProperties.Logger);
With an instance of the ILog interface, all log methods are written to the standard host log files by default.
logger.Error("My text"); logger.Fatal("should appear"); logger.Fatal("in the file");
using System; using AGI.Parallel.Client; using AGI.Parallel.Infrastructure; using AGI.Parallel.Infrastructure.Logging; namespace CodeSamples { class Program { static void Main(string[] args) { using (IJobScheduler scheduler = new ClusterJobScheduler("localhost")) { scheduler.Connect(); Job job = scheduler.CreateJob(); job.AddTask(new WriteSomeToLog()); job.Submit(); job.WaitUntilDone(); } /* * Go to %ALLUSERSPROFILE%\AGI\STK Parallel Computing Server 2.9\logs to inspect the log files. */ } [Serializable] 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"); } } } }
Logging can be important for debugging, tracing, and post-mortem analysis. The ILog interface provides "free" logging within tasks. The main advantage to using the ILog interface versus a custom logging mechanism is that ILog is tightly integrated with the existing logging infrastructure. For instance, right clicking on a task within the monitoring applications displays the user log messages in the same logs as the host.
STK Parallel Computing Server 2.9 API for .NET