Improve your visibility by redirecting console output to disk for your service in Service Fabric

Service Fabric have been announced recently and we all want to start playing with it. We often so that without going through the documentation. I don't know for you but I often do that ;)

The first thing I can recommend you is to read... Read about it. There is a LOT of stuff to absorb in Service Fabric and there is great documentation out here (links at the end of the article).

If you skip a concept or two and need help with what is happening there is a tip you can use.

What is happening?

What if you need to have more details about what is going on in your application? You need to setup ports or play with the firewall during bootstrap let say for your service and something is not happening the way you want?

You just need to add a element to your element in your ServiceManifest.xml and voila! You will end with the console output redirected.

  <CodePackage Name="Code" Version="1.0.0.0">
    <SetupEntryPoint>
      <ExeHost>
        <Program>HttpSetup.bat</Program>
        <ConsoleRedirection FileRetentionCount="5" FileMaxSizeInKb="128"/>
      </ExeHost>
    </SetupEntryPoint>
    <EntryPoint>
      <ExeHost>
        <Program>MyService.exe</Program>
      </ExeHost>
    </EntryPoint>
  </CodePackage>

You can surely use ETW which is great but you can rely on this mechanism for you service also. The redirect output to disk in your log folder.

    <EntryPoint>
      <ExeHost>
        <Program>MyService.exe</Program>
        <ConsoleRedirection FileRetentionCount="5" FileMaxSizeInKb="1024"/>
      </ExeHost>
    </EntryPoint>

Your logs should show up on the each nodes where your service is deployed, e.g. in the folder: C:\WFDevCluster\Data\Node.{NodeNumber}\Fabric\work\Applications{ApplicationName}\log

Want to learn more

I am the proud father of two little gems. A beer & wine enthusiasm. For everything else, I work and play with Azure at day, and I am an Azure MVP & Advisor at night.
Montreal, Canada