Improve Manageability Improve Manageability Microsoft.NET.

63
提提提提提提提提提提提 提提提提提提提提提提提 Improve Improve Manageability Manageability Microsoft .NET 技技技技 技技技

Transcript of Improve Manageability Improve Manageability Microsoft.NET.

Page 1: Improve Manageability Improve Manageability Microsoft.NET.

提昇應用程式的管理功能提昇應用程式的管理功能Improve Improve Manageability Manageability

Microsoft .NET 技術代言人林耀珍

Page 2: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 2

林耀珍林耀珍

經歷第三波資訊 技術總監育碁數位科技 總經理

專業認證與專長微軟 .NET 技術軟體開發流程,資訊系統規劃Microsoft MCSD/MCSE/MCDBA

物件導向技術, Rational OOAD 認證講師Lotus Notes principle CLP/CLI

J2EE

Page 3: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 3

目標與對象目標與對象

對象技術平台的決策人員軟體建構師系統分析師專案經理開發 .NET 應用程式管理功能的程式人員

目標開發 .NET 應用程式管理功能

Page 4: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 4

大綱大綱

Introduction

Configuration Management

Exception Management

Enterprise Instrumentation Framework

Logging Application block

Page 5: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 5

Application ArchitectureApplication Architecture

UI Components

UI Process Components

Data Access Components

Business Workflows

Business Components

Users

Business Entities

Service Agents

Service Interfaces

Data Sources

Services

Op

eration

al Man

agem

ent

Sec

urity

Co

mm

un

ication

Page 6: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 6

BenBeneefits of Improving fits of Improving Manageability Manageability

Development phasePinpoint bugs, performance issues

Deployment phaseConfigurable, Flexible

Operation phaseKnow what is going on in applications and able to manage them.

Provide sufficient information to track down what is going wrong.

Page 7: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 7

Application Management ChallengesApplication Management ChallengesFor the Support OrganizationFor the Support Organization

Application faults or issues are often detected first by users

Support staff need structured application information

Most tracing solutions are not intended for production deployment scenarios

Distributed applications magnify these challengesEvents fired from an application across multiple servers are hard to correlate

Page 8: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 8

Application Management ChallengesApplication Management ChallengesFor the Development OrganizationFor the Development Organization

No unified instrumentation APIDevelopers are forced to use different eventing, tracing, or logging solutions

Or, more often, avoid instrumentation entirely

Firing an event must be as simple and low-profile as possible

Developers are often forced to determine event routing within code

Page 9: Improve Manageability Improve Manageability Microsoft.NET.

Configuration Management Configuration Management Application BlockApplication Block- CMAB- CMAB

Page 10: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 10

App/Web .configApp/Web .config

ProblemsSimple data

Configuration.AppSettings[“ConnString”]

Not secure

Read only

File storage only, not Flexible

<?xml version="1.0" encoding="utf-8" ?><configuration> <appSettings> <add key="ConnString" value="data source=(local);initial catalog=DB1;user id=sa;password=" /> ... </add> </appSettings></configuration>

Page 11: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 11

Purpose of Configuration Management Purpose of Configuration Management Application Block (CMAB)Application Block (CMAB)

Purpose:Standardize interface to Read/Write application configuration data

Supports complex data structures

Pluggable Storage provider

Pluggable Signing & Encryption provider

Cache configuration data

Page 12: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 12

Conceptual DesignConceptual Design

YourApplication

YourApplication

Application XML Configuration

- XML File- XML File- SQL Server- SQL Server- Registry- Registry- Custom- Custom

Configuration ManagerConfiguration Manager

Configuration Storage ProviderConfiguration Storage Provider

Data ProtectionProviderData ProtectionProvider - DPAPI

- BCL- Custom

Caching ServiceCaching Service

Configuration Section Handlers

Configuration Section HandlersConfiguration

Section Handlers

Configuration Section

Handlers

Configuration Section

Handlers

Configuration Section

Handlers

Data ProtectionProvider

Data ProtectionProvider

Data ProtectionProvider

Data ProtectionProvider

Storage Service ProviderStorage Service Provider

Storage Service ProviderStorage Service Provider

Pluggable Handler, Storage/protection provider

Page 13: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 13

CMAB UsageCMAB Usage//Read Default section, i.e. first section, HashTable data formatconfigData = ConfigurationManager.Read(sectionName);foreach( string key in configData.Keys ) list.Items.Add( new ListPair( key, configData[ key ] ) );// WriteConfigurationManager.Write(sectionName, configData );

<configuration> <configSections>

<section name="applicationConfigurationManagement“ … />

<section name="ApplConfig1“ … /> </configSections> <applicationConfigurationManagement > … </applicationConfigurationManagement> <ApplConfig1> <Entries> <Entry> <key xsi:type="xsd:string">freaky</key> <value xsi:type="xsd:string">chakra</value> </Entry> … </Entries> </AppConfig1></configuration>

Page 14: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 14

Handler and ProviderHandler and Provider

In the app.config / web.configDefine Configuration Section Handler

Define Configuration Storage Provider

Define Data Protection Provider

Define Cache parameters

Page 15: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 15

CMAB configurationCMAB configuration<configuration> <configSections>

<section name="applicationConfigurationManagement“ type=“MS.AppBlocks.CMAB" />

<section name="ApplConfig1“ type=“MS.AppBlocks.CMAB.XmlHashtableSectionHandler" /> </configSections>

<applicationConfigurationManagement ><configSection name="ApplConfig1"> <configCache enabled="true" refresh="1 * * * *" /> <configProvider assembly=“MS.AppBlocks.CMAB"

type=“MS.AppBlocks.CMAB.Storage.XmlFileStorage” encrypted="false" />

<protectionProvider assembly=“MS.AppBlocks.CMAB" type=“MS.AppBlocks.CMAB.DataProtection.BCLDataProtection"

</configSection> </applicationConfigurationManagement>

<ApplConfig1> <XmlSerializableHashtable xmlns:xsd=http://www.w3.org/2001/XMLSchema …> <Entries> <Entry> <key xsi:type="xsd:string">freaky</key> <value xsi:type="xsd:string">chakra</value> </Entry> </Entries> </AppConfig1></configuration>

Page 16: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 16

Configuration Setting SchemaConfiguration Setting Schema

Page 17: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 17

.NET Support for .NET Support for Configuration Management Configuration Management

<?xml version="1.0" encoding="utf-8" ?><configuration> <ConfigSections> <section name=“MyConfigSec" type=“MyConfigNS.Handler, MyConfigAssembly”/> </ConfigSections> <MyConfigSec> … </MyConfigSec></configuration>

Page 18: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 18

Implementation of Implementation of ConfigurationManager ConfigurationManager

//Configuration manager Read() & Write()public static object Read( string sectionName ){ cacheSettings = CacheFactory.Create( sectionName ); configReader = StorageReaderFactory.Create( sectionName ); configSectionNode = configReader.Read(); sectionHandler = ConfigSectionHandlerFactory.Create( sectionName ); config = sectionHandler.Create( null, null, configSectionNode ); cacheSettings[ cacheSettings.SectionName ] = config;}

public static void Write(string sectionName, object configValue){ storageReader = StorageReaderFactory.Create( sectionName ); storageWriter = (IConfigurationStorageWriter)storageReader; sectionHandler = ConfigSectionHandlerFactory.Create( sectionName ); sectionHandlerWriter = (IConfigurationSectionHandlerWriter)sectionHandler; xmlNode = sectionHandler.Serialize( configValue ); storageWriter .Write( xmlNode );}

Page 19: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 19

Implementation of Implementation of ConfigurationSectionHandlerConfigurationSectionHandler

public object Create(object parent,object configContext,XmlNode section){ foreach(XmlNode configChildNode in section.ChildNodes) { if (configChildNode.Name == "configSection" ) ProcessConfigSection( configChildNode, out sectionSettings, configSettings ); }}

void ProcessConfigSection( XmlNode configChildNode, ...){ foreach(XmlNode sectionChildNode in configChildNode.ChildNodes) { switch ( sectionChildNode.Name ) { case "configCache" :

ProcessConfigCacheSection( sectionChildNode, … ); break; case "configProvider" :

ProcessConfigProviderSection( sectionChildNode, … ); break; case "protectionProvider" :

ProcessProtectionProvider( sectionChildNode, … ); break; } }}

Page 20: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 20

Implementation of Implementation of XmlHashtableSectionHandlerXmlHashtableSectionHandler

object Create(object parent, object configContext, XmlNode section){ if( section.ChildNodes.Count == 0 ) return new Hashtable(); XmlSerializableHashtable xmlHt = (XmlSerializableHashtable)_xmlSerializer.Deserialize( new XmlNodeReader( section ) ); return xmlHt.InnerHashtable;}

XmlNode Serialize(object value){ StringWriter sw = new StringWriter( ); _xmlSerializer.Serialize( sw, new XmlSerializableHashtable( (Hashtable)value ) );

XmlDocument doc = new XmlDocument(); doc.LoadXml( sw.ToString() ); return doc.DocumentElement;}

Page 21: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 21

Implementation of Implementation of XmlFileStorageXmlFileStorage

public XmlNode Read(){ XmlDocument xmlDoc = new XmlDocument(); LoadXmlFile(...); XmlNode sectionNode = xmlDoc.SelectSingleNode(@"/configuration/" + SectionName);

if( _isSigned || _isEncrypted ) { XmlNode encryptedNode = sectionNode.SelectSingleNode( "encryptedData" ); XmlNode signatureNode = sectionNode.SelectSingleNode( "signature" ); byte[] hash =_dataProtection.ComputeHash( Encoding.UTF8.GetBytes( sectionData ) ); //Compare the hashes encryptedBytes = Convert.FromBase64String( sectionData ); decryptedBytes = _dataProtection.Decrypt( encryptedBytes ); sectionData = Encoding.UTF8.GetString( decryptedBytes ); ... } return section data;}

Page 22: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 22

CMAB SummaryCMAB Summary

Standard Read/Write interface to access application configuration data

Supports complex data structures

Pluggable Storage provider for flexibility

Pluggable Signing & Encryption provider for security

Cache configuration data for efficiency

Page 23: Improve Manageability Improve Manageability Microsoft.NET.

Exception Management Exception Management Application BlockApplication Block- EMAB- EMAB

Page 24: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 24

Exception Management Application Exception Management Application Block (EMAB)Block (EMAB)

Purpose:Make it simple and powerful to report that an exception has occurred (1 line of code)

Make it extensible and flexible to log errors however you want

Problems solved:Often exception code is unique and repeated in every application

Changing how your exceptions are logged meant changing your code

Difficult to pass context information up the stack

Page 25: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 25

Solution ConceptSolution Concept

Your Your ApplicationApplication

Publisher Publisher (event log)(event log)

Exception ManagerException Manager

Exception

Publisher Publisher (database)(database)

Publisher Publisher (text file)(text file)

Publisher Publisher (email)(email)

Page 26: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 26

EMAB UsageEMAB Usage

Publishing an exception:

Pluggable ‘Publishers’ of exception infoEvent Log as default.

try {…}catch (Exception ex){ ExceptionManager.Publish(ex);

}

Page 27: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 27

EMAB Configuration-1EMAB Configuration-1<configuration> <configSections> <section name="exceptionManagement" type="ExceptionManagerSectionHandler,..." /> </configSections> <exceptionManagement mode="on"> <publisher assembly="..." type="ExceptionPublisher" exclude="*" include="LogonException, ...; CustomAppException, ..."/>

<publisher assembly="..." type="ExceptionXMLPublisher" exclude="*" include="+BaseApplicationException, ..." exceptionFormat="xml" fileName="c:\QuickStartSamplesExceptionLog.xml"/> </exceptionManagement></configuration>

* Means all exceptions, + means the exception and its descendants

Page 28: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 28

EMAB Configuration-2EMAB Configuration-2

<configSections> <section name="exceptionManagement"

type=" Microsoft.ApplicationBlocks.ExceptionManagement.ExceptionManagerSectionHandler,Microsoft.ApplicationBlocks.ExceptionManagement" />

</configSections>

<exceptionManagement mode="on"> <publisher mode="on/off" assembly="AssemblyName" exclude=“[*]Type,Type" include=“[+]Type,Type" exceptionFormat="xml"

customattr = "value" /> <publisher mode="on" assembly="MyPublishers" type="PublishToEmail" Server="mail.ABC.com" User="Jeff" Password="XYZ" /></exceptionManagement>

Page 29: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 30

BaseApplicationException

The exception block provides a base application exception class from which all your exceptions inherit.

Has contextual information like MachineName, Thread, Login, DateTime, AppDomain

Has additional information collection for inserting custom pieces of data

class HeartAttackException : BaseApplicationException

{ ...

}

Page 30: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 31

Encounter An ExceptionEncounter An Exception

Throw an customized exceptionYour custom exceptions now have additional information passed up the stack.

publish your exception if you are at the top of the stack

HeartAttackException ex;

ex = new HeartAttackException();

ex.AdditionalInformation.Add("BloodPressure", "120/300");

ex.AdditionalInformation.Add("Pulse", 85);

ex.AdditionalInformation.Add("WhiteCount", 1000);

throw ex;

Page 31: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 32

Publish an ExceptionPublish an Exceptionprivate void btnLogon_Click(…){ try { if ( DoLogon(txtUserName.Text, txtPassword.Text) == true )

MessageBox.Show("Your Logon Was Successful"); else

MessageBox.Show("Logon failed”); } catch( LogonException lex){ // publish Exception using ExceptionManager ExceptionManager.Publish( lex ); MessageBox.Show(lex.Message); }}private bool DoLogon(string userName, string password){ try{ using (FileStream fs = new FileStream( "Accounts.dat",…)) {

return CheckUserDetails(fs, userName, password); } } catch (FileNotFoundException ex ) { throw new LogonException( "Internal Failure. User file not found", ex ); }}

Page 32: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 33

Tips for exception blocksTips for exception blocks

Throw an customized exception

Remember to publish your exception if you are at the top of the stack—Do not re-throw it.

If you choose to ignore the above tip, at least add exception handling into the

Thread_UnhandledException event (winforms)

Application_Error event (webforms)

To display an exception to the user, you still need a MessageBox call.

ExceptionManager.Publish just records it.

Page 33: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 34

Implementation of Implementation of BaseApplicationExceptionBaseApplicationException[Serializable]public class BaseApplicationException : ApplicationException{ public BaseApplicationException() : base() { InitializeEnvironmentInformation(); } public BaseApplicationException(string message) : base(message) { InitializeEnvironmentInformation(); } public BaseApplicationException(string message,Exception inner) : base(message, inner) { InitializeEnvironmentInformation(); } private void InitializeEnvironmentInformation() { machineName = Environment.MachineName; threadIdentity = Thread.CurrentPrincipal.Identity.Name; windowsIdentity = WindowsIdentity.GetCurrent().Name; ... }}

Page 34: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 35

Implementation of ExceptionManagerImplementation of ExceptionManager

void Publish(Exception exception, NameValueCollection additionalInfo){ ConfigurationSettings.GetConfig(...); PublishToDefaultPublisher(exception, additionalInfo); // or foreach(PublisherSettings Publisher in config.Publishers) PublishToCustomPublisher(exception, additionalInfo, Publisher);}

void PublishToCustomPublisher(...){ if (publisher.ExceptionFormat == PublisherFormat.Xml) { IExceptionXmlPublisher XMLPublisher = (IExceptionXmlPublisher)Activate(publisher.AssemblyName, publisher.TypeName); XMLPublisher.Publish(SerializeToXml(exception, additionalInfo),publisher.OtherAttributes); } else { IExceptionPublisher Publisher = (IExceptionPublisher)Activate(publisher.AssemblyName, publisher.TypeName); Publisher.Publish(exception, additionalInfo, publisher.OtherAttributes); }}

Page 35: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 36

Implementation of DefaultPublisherImplementation of DefaultPublisher

Get publisher’s source

Get custom exception info

Get BaseApplicationException info

Get stack trace

Write to target source

Page 36: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 37

SummarySummary

Register custom event sources by running installutil on your DLL

Understand exception management best practices

Build a ‘dump to text file’ publisher for development

Page 37: Improve Manageability Improve Manageability Microsoft.NET.

Enterprise Instrumentation FrameworkEnterprise Instrumentation FrameworkEIFEIF

Page 38: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 39

EIF EIF GoalsGoals

Monitor and Troubleshoot applications built on the .NET Framework

Integrate and unify disparate tracing, eventing, and logging technologies

Support Distributed Environment

Integrate with existing management tools and products

Page 39: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 40

EIF Core FeaturesEIF Core Features

Unified Instrumentation APIUnified model for tracing, eventing, and logging

Leverages WMI Infrastructure (System.Management.Instrumentation)

Structured WMI Event SchemaManageability contract between developers, quality assurance, and support staff

Configurable At-Source Event FilteringFire via WMI, Event Log, Windows Event Trace

Minimal cost for leaving instrumentation in production build

High-speed Diagnostic TracingEnables problem management for production applications

Enables tracing user “requests” along application business processes or services

Page 40: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 41

.NET Application.NET Application

Instrumentation APIInstrumentation API

Event FilteringEvent Filtering

WMIWMI EventEventTraceTrace

EventEventLogLog

TraceTraceLogLog

EventEventLogLog

WMIWMISubscriberSubscriber

Co

nfig

uratio

nC

on

figu

ration

Event SchemaEvent Schema

Application Application ObjectObject

Application Application ObjectObject

Event SourceEvent Source Event SourceEvent Source

Trace ReaderTrace Reader

Single Application ServerSingle Application Server

Event Sink

Page 41: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 42

Distributed ServersDistributed Servers

Distributed .NET ApplicationDistributed .NET Application

Application ServerApplication Server Application ServerApplication Server

Event SourceEvent Source Event SourceEvent Source

Event RoutingEvent Routing

WMIWMI EventEventTraceTrace

EventEventLogLog

TraceTraceLogLog

EventEventLogLog

WMIWMISubscriberSubscriber

TraceTraceReaderReader

Event SourceEvent Source Event SourceEvent Source

Event RoutingEvent Routing

WMIWMI EventEventTraceTrace

EventEventLogLog

TraceTraceLogLog

EventEventLogLog

WMIWMISubscribersSubscribers

TraceTraceReaderReader

Management ServerManagement Server

Management SuiteManagement Suite

Mgmt EventMgmt EventRepositoryRepository

SQLSQLTrace EventTrace EventRepositoryRepository

Event Sink

Page 42: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 43

EIF UsageEIF Usage

AssembliesMicrosoft.EnterpriseInstrumentation

Microsoft.EnterpriseInstrumentation.Schema

System.Configuration.Install

Event sourcesImplicit event source (application)TraceMessageEvent.Raise(“something happened");

Explicit event source

Page 43: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 44

Raise Event by Raise Event by Implicit Event SourceImplicit Event Source

using Microsoft.EnterpriseInstrumentation;using Microsoft.EnterpriseInstrumentation.Schema;

class MyComponent{ // some method public void DoWork() { // Raise an event TraceMessageEvent.Raise(“something happened"); }}

Page 44: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 45

EIF EIF Explicit Event SourceExplicit Event Source

// using statements...

class MyComponent { private static EventSource myEventSource = new EventSource(“MyEventSource");

public void DoWork() { TraceMessageEvent.Raise(myEventSource, “Important message-1"); // or TraceMessageEvent e = new TraceMessageEvent(); e.Message = “Important message-2"; myEventSource.Raise(e); }}

Page 45: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 46

EIFEIF Configuration Files Configuration Files

Default nameEnterpriseInstrumentation.config

Default locations*.exe—in the same directory as executable

Web applications—root of Web

Name and location configurable Define in web.config or app.config

Use appSettings section

Page 46: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 47

EIF ConfigurationEIF Configuration

Definition and control of: Event source

Event sink

WMI, event log, and Windows event tracing

Event categories, describing a set of related events

Event filters, which map event sources to specific event categories and event sinks

FilterBinding

Event Category

Event Sinks

Event Filter

Event Source

Events

Page 47: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 48

EIF EIF Event SchemasEvent Schemas

Events in the standard event schemaAdministrative events

Audit events

Error events

Trace events

Custom event schemasAdd additional events and change events

Page 48: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 49

Custom EventCustom Event

Include event schema definitions

Define custom event which is derived from standard event

Build & install & Register it

using System;using Microsoft.EnterpriseInstrumentation.Schema;

namespace MyCompany.EnterpriseInstrumentation.Schema{

public class CustomEvent : BaseEvent{

public CustomEvent() {}

public string CustomProperty1 = "Default property value";}

}

Page 49: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 50

EIF EIF Custom Event SinksCustom Event Sinks

Writing a custom event sinkDerive from EventSink abstract base class

Implement the constructor

Implement the Dispose method and virtual EventSink::Write() method

Use parameters in constructor to set up the event sink

Documents have example for MsmqEventSink

Page 50: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 51

Enables tracing user requests through a distributed application

Trace business services of the applicationCan flow across a distributed .NET application

Tracing is only activated only specific execution pathEvents get tagged with request context

Even if no tracing session is enabled

EIF Request TracingEIF Request Tracing

Page 51: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 52

Request-based Correlation Of EventsRequest-based Correlation Of EventsRequest Event SourceRequest Event Source

public class MyRequestTrace { public static RequestEventSource requestEventSource = new RequestEventSource(“My Request Authorization");

public void DoWork(){ RequestTrace myRequest = new RequestTrace(requestEventSource); try { TraceMessageEvent.Raise(“My message”); } finally { firstRequest.Dispose(); } }}

Page 52: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 53

Using EIF Request TracingUsing EIF Request Tracing

public class MyRequestTrace { public static RequestEventSource requestEventSource =

new RequestEventSource(“My Request Authorization"); public void DoWork() { // Request trace starts when the rti is created. using (RequestTrace rti = new RequestTrace(requestEventSource)) {

// do something …TraceMessageEvent.Raise(“My message”);

} }}

Page 53: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 54

SummarySummary

Enterprise Instrumentation FrameworkSignificantly improves enterprise customers’ ability to monitor and troubleshoot .NET applications

Integrates and unifies disparate tracing, eventing, and logging technologies

Integrates with existing management tools and products via WMI and the Windows Event Log

Provides a starting point for distributed trace-log aggregation and analysis

Page 54: Improve Manageability Improve Manageability Microsoft.NET.

Logging Application BlockLogging Application BlockLABLAB

Page 55: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 56

LAB LAB OverviewOverview

Provides extensions to the Enterprise Instrumentation Framework (EIF) addressing common usage scenarios for loggingEnable control of what and how much information is loggedEnable logged information to be consumed by different monitoring/analysis applications with little or no customizationProvide useful and rich information in the logged dataSupport for logging in distributed applicationsEnable scenarios like metering and workflow tracing for web services

Page 56: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 57

LABLAB Extensions to EIF Extensions to EIF

Configurable log levels

Enhanced information in the published events

Event information available in a easily consumable XML format

Asynchronous logging (store and forward using MSMQ)

Centralized logging (SQL database as the log store)

Formatting of event information (XSLT transformation)

Request tracing (Workflow tracing) for Web services

Metering for Web services

EIF publisher for Exception Management Block

Page 57: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 58

LAB Solution conceptLAB Solution concept

Event Schema

Application

EIF Instrumentation API

TraceLog

EventLog

WMI

Event Sinks

Trace Log

Event Log

WMI

EIF Config

WSEFilters

SQL

SQL

MSMQ

MSMQUser DevelopedUser Developed

PnP DevelopedPnP Developed

Ships out of the BoxShips out of the Box

PnP ModifiedPnP Modified

Page 58: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 59

Design of Design of Formatting of Event InformationFormatting of Event Information

Client Client ApplicationApplication

ClientClientApp ConfigApp Config

EIF APIEIF API

EIF EIF ConfigConfig

Formatter Formatter FactoryFactory

CustomFormatter2CustomFormatter2

CustomFormatter1CustomFormatter1

XSLTFormatterXSLTFormatter

Logging BlockLogging BlockEvent SinkEvent Sink

Log Log StoreStore

Page 59: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 60

Request Tracing for Web ServicesRequest Tracing for Web Services

Capability to trace a request from origin through completion even when the request flows across machine, domain boundaries when using Web Services.

Event correlation information carried as part of the Soap Header.

Page 60: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 61

Design of Design of Request Tracing for WSRequest Tracing for WS

Request TracingInput Filter

Request TracingOutput Filter

EIF

Logging BlockEvent Sinks

(SQL, MSMQ, WMI and Event

Log)

EIF Config

XSLT basedFormatter

Log Store

WSE Pipeline

My Web Service

Page 61: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 62

SummarySummary

Enable control of what and how much information is loggedEnable logged information to be consumed by different monitoring/analysis applications with little or no customizationProvide useful and rich information in the logged dataSupport for logging in distributed applicationsEnable scenarios like metering and workflow tracing for web services

Page 62: Improve Manageability Improve Manageability Microsoft.NET.

.NET技術代言人 林耀珍 2004/03/24 63

ConclusionConclusion

Manageability play an important role to minimize TCO.

Manageability is helpful to development, deployment, and operation management.

Application building blocks are most effective when used with .NET Application Architecture and SOA.

.NET Architecture

Patterns & Practices

Page 63: Improve Manageability Improve Manageability Microsoft.NET.

Questions…Questions…

Microsoft .NET 技術代言人林耀珍