When deploying applications in Service Fabric, which are not necessarily developed to run in Service Fabric host, you can redirect standard output to log files. Assume you have a console application which you want to run in Service Fabric cluster as microservice. Assuming that this application is writing some messages to console standard output, you will lose all that messages if you run it in host such Service Fabric.
To make this working you can redirect the standard output to the log file, by using following configuration:
<EntryPoint> <ExeHost> <Program>Console.exe</Program> <Arguments>:)</Arguments> <WorkingFolder>CodePackage</WorkingFolder> <ConsoleRedirection FileRetentionCount="5" FileMaxSizeInKb="2048"/> </ExeHost> |
ConsoleRedirection is element which redirects OUT-stream of console application in the log file. FileRetentionCount defines the number of log files in working directory. FileMaxSizeInKb is the maximum size of the file.
Please note that the log-file is persisted at each node of the service. Following picture shows how to find location of the file.
Following picture shows the content of the folder, which contains log-files.
I used following code to write output:
using (FabricRuntime fabricRuntime = FabricRuntime.Create()) { while (true) { Console.WriteLine("Running at {0}", DateTime.Now ); Thread.Sleep(1000); } } |
And, here is the content of the log-file:
Console started :) Running at 1/10/2016 6:14:32 PM Running at 1/10/2016 6:14:34 PM Running at 1/10/2016 6:14:35 PM Running at 1/10/2016 6:14:36 PM Running at 1/10/2016 6:14:37 PM Running at 1/10/2016 6:14:38 PM |
Posted
Jan 12 2016, 06:27 AM
by
Damir Dobric