THE SQL Server Blog Spot on the Web

Welcome to SQLblog.com - The SQL Server blog spot on the web Sign in | |
in Search

Master Data Services Team

Blog for the Microsoft SQL Server Master Data Services (MDS) team. Blog posts are contributed by various team members.

Trace Logging in SQL Server 2008 R2 Master Data Services

(this post was contributed by Val Lovicz, Principal Program Manager on the MDS Team) 

Once you’ve installed Master Data Services (MDS), you may find the trace logging feature useful for error diagnostics and support requests as well as monitoring of application usage and performance.  This post covers the steps to turn on and configure trace logging.  Specifically, this post covers tracing to a text log file.  Other logging mechanisms are supported and will be covered in future posts and SQL Server Books Online.

Background

Master Data Services consists of an ASP.NET web application (Master Data Manager) and a WCF service, both hosted in IIS, plus a SQL Server 2008 R2 database.  Both Master Data Manager requests and external calls to the web services API end-point are handled by a common service layer.  The service layer can log each each operation request/response as well as important events and errors.

The web.config file

As an administrator with access to files on the IIS web server, you can enable logging by modifying the MDS web.config file.  This file is located in the web application folder: <program files dir>\Microsoft SQL Server\Master Data Services\WebApplication.

Caution: Updating web.config will cause the MDS application domain in IIS to recycle.  Existing user sessions will lose cached information and users may experience session errors or slow page loads.  Perform changes at off-peak times if possible.

The file snippet below shows the diagnostics section from the originally installed file. Note that switchValue is set to “Off”. Additionally, the example lines that follow are commented out. These lines are examples for adding trace listeners of various types.

<system.diagnostics>
<sources>
<!-- Adjust the switch value to control the types of messages that should be logged. -->
<source name="MDS" switchType="System.Diagnostics.SourceSwitch" switchValue="Off">
<listeners>
<!-- Enable and configure listeners as desired to obtain trace messages. -->
<!-- <add name="LogFileListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="MdsTrace.log" traceOutputOptions="DateTime" /> -->
<!-- <add name="EtwListener" type="System.Diagnostics.Eventing.EventProviderTraceListener, System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"
initializeData="{F2A341B8-CA5F-49ad-B00C-A82D3FCF948B}"/> -->
<!-- <remove name="Default"/> -->
</listeners>
</source>
</sources>
<trace autoflush="true" />
</system.diagnostics>

Turning on log file tracing

To enable logging, change switchValue to “All” or another valid value as described below in Table 2. To enable the output to a log file, uncomment the LogFileListener line as shown in the file snippet below.

<system.diagnostics>
<sources>
<!-- Adjust the switch value to control the types of messages that should be logged. -->
<source name="MDS" switchType="System.Diagnostics.SourceSwitch" switchValue="All">
<listeners>
<!-- Enable and configure listeners as desired to obtain trace messages. -->
<add name="LogFileListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="MdsTrace.log" traceOutputOptions="DateTime" />
<!-- <add name="EtwListener" type="System.Diagnostics.Eventing.EventProviderTraceListener, System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"
initializeData="{F2A341B8-CA5F-49ad-B00C-A82D3FCF948B}"/> -->
<!-- <remove name="Default"/> -->
</listeners>
</source>
</sources>
<trace autoflush="true" />
</system.diagnostics>

File name and path

The initializeData value is the name of the log file. This may be modified to another name or to include a desired path. If the path is not specified then the file will default to the web application directory path (where web.config resides).

Important Note: The service account for the MDS application pool must have write access to the log file location.

Logging level of detail

Table 1 below describes the categories of trace events that may be logged, sorted with the most important / critical events at the top.  Table 2 below lists the valid settings for the logging switchValue; this setting may be adjusted to produce the right amount of logging details to suit the situation.

Table 1 - MDS logging event types

Event Type

Description

Critical

a fatal error or application crash

Error

a recoverable error

Warning

a noncritical problem

Information

an informational message

Verbose

a debugging trace message

Start

starting of a logical operation

Stop

stopping of a logical operation

Table 2 - SwitchValue settings for logging

Setting

What is logged:

Off

nothing

Error

errors only

Warning

errors and warnings

Information

errors, warnings, informational messages

Verbose

“Information” plus additional debugging trace information including API requests and responses in XML format

ActivityTracing

start and stop events only

All

“Verbose” plus “ActivityTracing”

Log setting recommendations

  • For normal operation, use the “Off” setting to avoid logging altogether or use the “Error” or “Warning” settings which will keep the log small while alerting administrators to problems.
  • Use the “All” setting for support / troubleshooting situations. 
  • Use “ActivityTracing” for performance measurement or usage monitoring.
  • Use “Information” only if prepared to periodically check and clean logs. The logs could get lengthy with this setting. This setting is helpful for tracking usage and usage patterns.
  • Do not use “Verbose” or “All” under normal operating conditions as the volume of data logged will negatively affect performance.

Creating a log for product support – step by step

In situations where an unexpected error occurs and further diagnostics are required, it is helpful to create a log file that traces the events leading up to the problem along with the service requests and responses.

To produce a concise and helpful log file, perform the following steps.

Caution: Updating web.config will cause the MDS application domain in IIS to recycle.

1. If possible, stop the MDS application pool in IIS Manager (warning: do this only if the application can be taken off line)

2. If possible, move or delete the current log file (if one already exists).

3. Open the web.config file with a text editor (<program files>\Microsoft SQL Server\Master Data Services\WebApplication\web.config).

4. Find the system.diagnostics section.

5. Change the switchValue to All or ActivityTracing and uncomment the log file line as shown in Sample 3.

a. Use the “All” switchValue for error diagnostics.

b. Use the “ActivityTracing” switchValue for performance diagnostics.

c. The MdsTrace.log file name can be prefixed with a path if desired.

6. If the application pool was previously stopped:

a. Then: start the MDS application pool in IIS

b. Else: wait for the log file to appear after some time and web application activity. The web application will periodically reload configuration settings from the file (should be within minutes).

7. Reproduce the problem - perform the actions / requests that led to the error.

8. If able to stop application pool:

a. Then:

i. stop the application pool

ii. retrieve the log file (may need to wait for processes to finish; there could be a delay after stopping the app pool)

b. Else:

i. Open the log file with an editor that doesn’t lock the file and copy the relevant tracing messages.

9. Open the web.config file with a text editor and change the switchValue back to Off or the prior value.

10. Start the application pool if stopped.

Error Handling

All service operations return an array or collection of errors within the OperationResult object of a response message. When an error occurs, the error array is also serialized to XML and written to the web application log file for certain switchValue settings as described above.

Example of an API response error that has been written to the log file:

MDS Error: 0 : <ArrayOfError xmlns="http://schemas.microsoft.com/sqlserver/masterdataservices/2009/09" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Error>
<Code>110003</Code>
<Context>
<FullyQualifiedName>Model1</FullyQualifiedName>
<Identifier>
<Id>00000000-0000-0000-0000-000000000000</Id>
<Name>Model1</Name>
<InternalId>0</InternalId>
</Identifier>
<Type>Model</Type>
</Context>
<Description>The name already exists. Type a different name.</Description>
</Error>
</ArrayOfError>
DateTime=2009-12-10T20:48:05.6949548Z

Error object contents

Table 3 - As shown in the example above, each error includes the following data properties.

Property

Description

Code

The unique error number identifying the type of error

Description

Localized error message text

Context.FullyQualifiedName

The fully qualified name of the object involved in the error

Some names are only unique within their context. An entity would be qualified with a Model name prefix such as ModelName : EntityName.

Context.Type

The type of object involved in the error

Context.Identifier

The identifier of the object involved in the error

Context.Identifier.Id

The unique GUID of the object, if specified or available

Context.Identifier.Name

The name of the object, if specified or available

Context.Identifier.InternalId

Deprecated – do not use

Published Tuesday, January 05, 2010 12:26 PM by mattande
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

Leave a Comment

(required) 
(required) 
Submit
Powered by Community Server (Commercial Edition), by Telligent Systems
  Privacy Statement