Tracing
AppHarbor supports tracing log messages to your application's log stream from background and web workers. This allows you to effortlessly log messages using built-in .NET tracing features. The tracing integration builds on ETW (Event Tracing for WIndows), so you can also integrate directly with that using injected event provider id.
Application performance is unaffected by the delivery of log messages as this takes place completely out of process. Note however messages are buffered for about a second and that some messages may be dropped if you’re writing excessively to the trace output.
You can set the current trace level on the application's Logging
page. There are currently 4 trace levels available:
All
, Warning
, Error
and
None
. Updating the trace level will dynamically update
the tracing configuration without redeploying or restarting your
application.
Trace messages are automatically associated with the worker emitting them allowing you to filter and diagnose individual workers.
Below are a few examples of how to use tracing in your application.
System.Diagnostics.Trace
When tracing is enabled, AppHarbor configures your application
with an EventProviderTraceListener as a default trace listener.
This means you can use the Trace
class without any
configuration to trace messages to your log:
Trace.TraceError(“Foo”)
System.Diagnostics.TraceSource
var traceSource = new TraceSource("AppHarborTraceSource", defaultLevel: SourceLevels.All);
traceSource.TraceEvent(TraceEventType.Critical, 0, "Foo");
NLog target
<targets>
<target xsi:type="Trace" name="String" layout="Layout" />
</targets>
log4net TraceAppender
<appender name="TraceAppender" type="log4net.Appender.TraceAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
Using ASP.NET healthmonitoring
With ASP.NET health monitoring you monitor the status of your application and track a number of different events. You can find supported events and configuration details in this article.
This example configuration will trace all unhandled exceptions as well as trace application lifecycle events (application start/stop etc):
<healthMonitoring enabled="true" heartbeatInterval="0">
<providers>
<add name="TraceEventProvider" type="System.Web.Management.TraceWebEventProvider,
System.Web,Version=4.0.0.0, Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" />
</providers>
<profiles>
<add name="Trace" minInstances="1" maxLimit="Infinite" minInterval="00:00:00" />
</profiles>
<rules>
<remove name="All Errors"/>
<add name="All Errors"
eventName="All Errors"
provider="TraceEventProvider"
profile="Default"
minInstances="1"
maxLimit="Infinite"
minInterval="00:00:05"
custom="" />
<remove name="Application Events"/>
<add name="Application Events"
eventName="Application Lifetime Events"
provider="TraceEventProvider"
profile="Default"
minInstances="1"
maxLimit="Infinite"
minInterval="00:00:05"
custom="" />
</rules>
</healthMonitoring>
ETW
You can integrate directly with ETW
(Event Tracing for Windows).aspx). An event provider id is
generated per-worker and is injected in your
appSettings
. You can retrieve it like so:
ConfigurationManager.AppSettings["appharbor.worker.event_provider_id"];