Skip to content

Instantly share code, notes, and snippets.

@sandrinodimattia
Created August 27, 2012 23:27
Show Gist options
  • Save sandrinodimattia/3493335 to your computer and use it in GitHub Desktop.
Save sandrinodimattia/3493335 to your computer and use it in GitHub Desktop.
Output logs in the emulator
public class WebRole : RoleEntryPoint
{
private TraceSource CreateTraceSource()
{
var traceSource = new TraceSource("SampleApp", SourceLevels.All);
traceSource.Listeners.Add(
Activator.CreateInstance(
Type.GetType("Microsoft.ServiceHosting.Tools.DevelopmentFabric.Runtime.DevelopmentFabricTraceListener, Microsoft.ServiceHosting.Tools.DevelopmentFabric.Runtime, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")) as TraceListener);
return traceSource;
}
public override bool OnStart()
{
if (RoleEnvironment.IsEmulated)
{
var traceSource = CreateTraceSource();
traceSource.TraceInformation("Instance {0} started.", RoleEnvironment.CurrentRoleInstance.Id);
}
RoleEnvironment.Changing += OnChanging;
return base.OnStart();
}
private void OnChanging(object sender, RoleEnvironmentChangingEventArgs e)
{
if ((e.Changes.Any(change => change is RoleEnvironmentConfigurationSettingChange)))
{
e.Cancel = true;
}
if (RoleEnvironment.IsEmulated)
{
var traceSource = CreateTraceSource();
traceSource.TraceInformation("RoleEnvironment.Changing for {0}:", RoleEnvironment.CurrentRoleInstance.Id);
foreach (RoleEnvironmentChange change in e.Changes)
{
traceSource.TraceInformation(" > {0}", change.GetType());
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment