Reputation: 10969
I had an existing WCF web service that contains three WebGet handlers in one .cs file. These handlers make appropriate calls to other .cs files to handle the action.
Now, I created an Azure project based on this web service by creating the Azure project and adding the existing solution. Now, I would like to use Trace.WriteLine for logging. I set up the .cscfg, .csdef, and Web.config files to allow for logging to Azure storage.
However, I don't know where to set up the following info:
//Get the default configuration
DiagnosticMonitorConfiguration dmc = DiagnosticMonitor.GetDefaultInitialConfiguration();
//Set the schedule to transfer logs every 10 mins to the storage
dmc.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(10);
//Start Diagnostics Monitor with the storage account configuration
DiagnosticMonitor.Start("DiagnosticsConnectionString",dmc);
I tried placing it in a separate internal static class that contains a logger method, but I get a RoleEnvironmentException:error when I run the web service.
Since I do not have an OnStart() method in my web service class with the three WebGets, where do I put it to make sure that I have the diagnostic monitor started correctly, so that I can use Trace.WriteLine?
Upvotes: 0
Views: 683
Reputation: 1947
Late follow up for future viewers... In my case I had enabled Diagnostics in > Roles > . So when I added DiagnosticMonitor.Start to Global.aspx > Application_Start it basically started again. Since I wanted to customize the configuration I just disabled the built-in diagnostics feature in the role's configuration.
Upvotes: 1
Reputation: 35905
Try to :
Try to find an equivalent to BeginRequest in WCF.
Upvotes: 1
Reputation: 9399
This configuration code doesn't specifically need to be set on every class that is running code, it simply needs to be run once when your web role starts. The usual place to do this is in the RoleEntryPoint
. Because you created this project and then added it to your cloud project, then you won't have a RoleEntryPoint
with an OnStart()
method that you can override. But that doesn't mean that you can't have one.
You have two options;
Microsoft.WindowsAzure.ServiceRuntime.RoleEntryPoint
and override the OnStart()
to setup your diagnostics (this would be my preferred option)Application_Start
in the global.asaxUpvotes: 2