I have looked at a lot of different Azure and Wcf service examples. I have configured a trace listener and much trace information is appearing in the associated log file; however, I don't see the results of my Trace.WriteLine requests. I do see my Trace.WriteLine requests in the Azure debugger output panel.. Where is the output of these requests persisted?
From my Web.config
<system.diagnostics>
<sources>
<source propagateActivity="false" name="System.ServiceModel"
switchValue="Verbose,ActivityTracing">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="" />
</add>
<add name="AzureLocalStorage">
<filter type="" />
</add>
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging" switchValue="Information">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="" />
</add>
<add name="AzureLocalStorage">
<filter type="" />
</add>
</listeners>
</source>
</sources>
<sharedListeners>
<add type="WCFServiceWebRole1.AzureLocalStorageTraceListener, WCFServiceWebRole1"
name="AzureLocalStorage">
<filter type="" />
</add>
</sharedListeners>
<trace autoflush="true" />
From my AzureLocalStorageTraceListener.cs
public class AzureLocalStorageTraceListener : XmlWriterTraceListener
{
public AzureLocalStorageTraceListener()
: base(Path.Combine(AzureLocalStorageTraceListener.GetLogDirectory().Path, "WCFServiceWebRole1.svclog"))
{
}
public static DirectoryConfiguration GetLogDirectory()
{
DirectoryConfiguration directory = new DirectoryConfiguration();
directory.Container = "wad-tracefiles";
directory.DirectoryQuotaInMB = 10;
directory.Path = RoleEnvironment.GetLocalResource("WCFServiceWebRole1.svclog").RootPath;
return directory;
}
}
The AzureLocalStorageTraceListener you created simply logs to a *.svclog file. If you want to output logs to the emulator there are a few things you should take care of:
Add the DevelopmentFabricTraceListener to your shared listeners (this will also work for the 1.7 SDK)
<add type="Microsoft.ServiceHosting.Tools.DevelopmentFabric.Runtime.DevelopmentFabricTraceListener, Microsoft.ServiceHosting.Tools.DevelopmentFabric.Runtime, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="Emulator">
<filter type="" />
</add>
Make sure the switch value is correct (you could try the value All to get started)
Change the logging level in the emulator (by right clicking the icon at the top right of the screen).
Related
I have a WCF service which has logging enabled. But when i do not mention the path for the logs, the svc logs are getting created in "C:\" in this location. Is this the default location for the logs if we are not implicitly mentioned?
<system.diagnostics>
<sources>
<source name="System.ServiceModel.MessageLogging" switchValue="Verbose,ActivityTracing">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="" />
</add>
<add name="ServiceModelMessageLoggingListener">
<filter type="" />
</add>
</listeners>
</source>
<source propagateActivity="true" name="System.ServiceModel" switchValue="Error">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="" />
</add>
<add name="ServiceModelTraceListener">
<filter type="" />
</add>
</listeners>
</source>
</sources>
<sharedListeners>
<add initializeData="\Logfilename.svclog" type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="ServiceModelTraceListener" traceOutputOptions="Timestamp">
<filter type="" />
</add>
</sharedListeners>
</system.diagnostics>
You're starting your path (\Logfilename.svclog) with a backslash (\), meaning "root of the current drive".
If you want the current (bin) directory, remove the backslash.
When reviewing IIS logs I see some HTTP 400 responses. To diagnose the problem, I have enabled SVCTrace via the following configuration....
<system.diagnostics>
<sources>
<source name="System.ServiceModel.MessageLogging" switchValue="Warning, ActivityTracing">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="" />
</add>
<add name="ServiceModelMessageLoggingListener">
<filter type="" />
</add>
</listeners>
</source>
<source name="System.ServiceModel" switchValue="Warning, ActivityTracing"
propagateActivity="true">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="" />
</add>
<add name="ServiceModelTraceListener">
<filter type="" />
</add>
</listeners>
</source>
</sources>
<sharedListeners>
<add initializeData="C:\temp\messages.svclog"
type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp">
<filter type="" />
</add>
<add initializeData="C:\temp\tracelog.svclog"
type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
name="ServiceModelTraceListener" traceOutputOptions="Timestamp">
<filter type="" />
</add>
</sharedListeners>
</system.diagnostics>
While IIS continues to receive HTTP 400 responses, these do not show in the SVCTrace file. I assume this is because a HTTP 400 means bad request, and therefore a bad request never made to WCF to be included in a trace file. Is this an incorrect assumption?
I'm trying to diagnose a WCF service that is self-hosted in a relatively simple service host process (Service.exe).
I have Service.exe.config configured thus:
<?xml version="1.0" ?>
<configuration>
<system.diagnostics>
<sources>
<source name="System.ServiceModel"
switchValue="All"
propagateActivity="true">
<listeners>
<add name="traceListener"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData= "c:\temp\Service.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>
<system.serviceModel>
<diagnostics>
<messageLogging maxMessagesToLog="1"
maxSizeOfMessageToLog="2147483647"
logEntireMessage="true"
logMessagesAtServiceLevel="true"
logMalformedMessages="true"
logMessagesAtTransportLevel="true">
</messageLogging>
</diagnostics>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0"
sku=".NETFramework,Version=v4.0" />
</startup>
</configuration>
When I look at the resulting svclog file, I see many trace events being logged (I expected only the first message to be logged), and none of the messages being traced show a message body (only headers).
I'm sure I must be missing something simple here, but I don't see it.
UPDATE: When I look at the WCF Config Editor, there are two sections under "Diagnostics": MessageLogging and Tracing. When I click the "EnableMessageLogging" link, my config file gets updated:
<system.diagnostics>
<sources>
<source propagateActivity="true" name="System.ServiceModel" switchValue="All">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="" />
</add>
<add initializeData="c:\temp\MessageBodyTracing.svclog" type="System.Diagnostics.XmlWriterTraceListener"
name="traceListener">
<filter type="" />
</add>
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging" switchValue="Warning, ActivityTracing">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="" />
</add>
<add name="ServiceModelMessageLoggingListener">
<filter type="" />
</add>
</listeners>
</source>
</sources>
<sharedListeners>
<add initializeData="c:\users\me\documents\visual studio 2010\projects\messagebodytracing\messagebodytracing\app_messages.svclog"
type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp">
<filter type="" />
</add>
</sharedListeners>
</system.diagnostics>
I guess the source named System.ServiceModel.MessageLogging is the key - I hadn't seen that in any documentation of message tracing...
Try to add:
<endToEndTracing propagateActivity="true" activityTracing="true" messageFlowTracing="true" />
in your diagnostics node, under messageLogging.
Set LogEntireMessage to true under Diagnostics->MessageLogging in the Service configuration Editor
I've been trying to catch exceptions in my WCF service and store them in a log file (I don't want the client to get any specific error message at this point).
Having read a few tutorials online I've added some logging configuration to the <system.diagnostics> section of web.config:
<sources>
<source name="System.ServiceModel.MessageLogging" switchValue="Error">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="" />
</add>
<add name="ServiceModelMessageLoggingListener">
<filter type="" />
</add>
</listeners>
</source>
<source name="System.ServiceModel" switchValue="Error" propagateActivity="true">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="" />
</add>
<add name="ServiceModelTraceListener">
<filter type="" />
</add>
</listeners>
</source>
</sources>
<sharedListeners>
<add initializeData="C:\inetpub\wwwroot\myApp\logs\Web_messages.svclog" type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp">
<filter type="" />
</add>
<add initializeData="C:\inetpub\wwwroot\myApp\logs\Web_tracelog.svclog" type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="ServiceModelTraceListener" traceOutputOptions="Timestamp">
<filter type="" />
</add>
</sharedListeners>
In the event of an exception I've been tried using Debug.WriteLine and Trace.WriteLine but nothing is getting written to the tracefile.
I know IIS / WCF can write to the log file, if I set the switchValue for either of the sources to be Verbose I get plenty of information (too much to be of use), but I only want the exception code.
Try this,
consider the following class
public class TraceUtility
{
private TraceSource trcSrc;
public TraceUtility(string traceSourceName)
{
if (string.IsNullOrEmpty(traceSourceName))
{
throw new ArgumentNullException(traceSourceName);
}
trcSrc = new TraceSource(traceSourceName);
}
public void TraceError(int id, string message)
{
trcSrc.TraceEvent(TraceEventType.Error, id, message);
}
public void TraceError(int id, string message, params object[] args)
{
trcSrc.TraceEvent(TraceEventType.Error, id, message, args);
}
public void TraceError(string message)
{
TraceError(0, message);
}
public void TraceError(string message, params object[] args)
{
TraceError(0, message, args);
}
}
Now add the following config section to your configuration file
<system.diagnostics>
<sources>
<source name="xyz" switchName="AllSwitch">
<listeners>
<add name="xyzListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="C:\Traces\xyz.txt" traceOutputOptions="DateTime" />
</listeners>
</source>
</sources>
<switches>
<add name="AllSwitch" value="All"/>
<add name="OnlyErrors" value="Error"/>
</switches>
<trace autoflush="true" indentsize="3"/>
</system.diagnostics>
Finally, in order to use it:
TraceUtilitiy trcSrc = new TraceUtility("xyz");
trcSrc.TraceError("Error: {0}", "Your error description");
Note that you can add trace methods for information and warnings to the trace utility class just as I did with the trace error methods.
Hope this is what you are seeking for.
EDIT:
Your other code did not run because you did not specify a custom listener to the System.Diagnostics.Trace class. To do so add the following section into your config:
<system.diagnostics>
<trace autoflush="true" indentsize="4">
<listeners>
<remove name="DefaultTraceListener" />
<add name="LogFileListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="C:\Traces\xyz1.txt" />
</listeners>
</trace>
</system.diagnostics>
and try using your old code. Hope this will de-baffle you ;)
I am trying to add a WCF RIA service to an existing website.
When I load the page I get a "Load Operation failed for query"
I fire up fiddler2 and get
The resource cannot be found.
<body bgcolor="white">
<span><H1>Server Error in '/' Application.<hr width=100% size=1 color=silver></H1>
<h2> <i>The resource cannot be found.</i> </h2></span>
<font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">
<b> Description: </b>HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
<br><br>
<b> Requested URL: </b>/Services/WCSynthesis-Web-WCSynthDomainService.svc/binary<br><br>
<hr width=100% size=1 color=silver>
So then I try to get the WCF Loggging working
but the Services is empty and so is the
C:\Users\markgreenway\Desktop\My Dropbox\WCSynthesis\WCSynthesis.Web\Web_messages.svclog
File
alt text http://web7.twitpic.com/img/48823384-d9b0438ce6a54d9286856ee83dc8447a.4b227a17-scaled.jpg
So I cannot view anything in the Service Trace Viewer
my System.Diagnostics
<system.diagnostics>
<sources>
<source name="System.ServiceModel.MessageLogging" switchValue="Warning, ActivityTracing">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="" />
</add>
<add name="ServiceModelMessageLoggingListener">
<filter type="" />
</add>
</listeners>
</source>
<source propagateActivity="true" name="System.ServiceModel" switchValue="Warning, ActivityTracing">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="" />
</add>
<add name="ServiceModelTraceListener">
<filter type="" />
</add>
</listeners>
</source>
</sources>
<sharedListeners>
<add initializeData="C:\Users\markgreenway\Desktop\My Dropbox\WCSynthesis\WCSynthesis.Web\Web_messages.svclog"
type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp">
<filter type="" />
</add>
<add initializeData="C:\Users\markgreenway\Desktop\My Dropbox\WCSynthesis\WCSynthesis.Web\Web_tracelog.svclog"
type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
name="ServiceModelTraceListener" traceOutputOptions="Timestamp">
<filter type="" />
</add>
</sharedListeners>
I did add a reference to
• Microsoft.RiaServices.Tools
and it started to work (Fiddler Gave me some real information)