1 / 63

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

提昇應用程式的管理功能 Improve Manageability . Microsoft .NET 技術代言人 林耀珍. 林耀珍. 經歷 第三波資訊 技術總監 育碁數位科技 總經理 專業認證與專長 微軟 .NET 技術 軟體開發流程,資訊系統規劃 Microsoft MCSD/MCSE/MCDBA 物件導向技術, Rational OOAD 認證講師 Lotus Notes principle CLP/CLI J2EE. 目標與對象. 對象 技術平台的決策人員 軟體建構師 系統分析師 專案經理 開發 .NET 應用程式管理功能的程式人員

kaiser
Download Presentation

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

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 提昇應用程式的管理功能Improve Manageability Microsoft .NET 技術代言人 林耀珍

  2. 林耀珍 • 經歷 第三波資訊 技術總監 育碁數位科技 總經理 • 專業認證與專長 微軟 .NET 技術 軟體開發流程,資訊系統規劃 Microsoft MCSD/MCSE/MCDBA 物件導向技術,Rational OOAD 認證講師 Lotus Notes principle CLP/CLI J2EE .NET技術代言人 林耀珍 2004/03/24

  3. 目標與對象 對象 • 技術平台的決策人員 • 軟體建構師 • 系統分析師 • 專案經理 • 開發.NET 應用程式管理功能的程式人員 目標 • 開發.NET 應用程式管理功能 .NET技術代言人 林耀珍 2004/03/24

  4. 大綱 Introduction Configuration Management Exception Management Enterprise Instrumentation Framework Logging Application block .NET技術代言人 林耀珍 2004/03/24

  5. Users Communication Operational Management Security UI Components UI Process Components Service Interfaces Business Workflows Business Components Business Entities Data Access Components Service Agents Data Sources Services Application Architecture .NET技術代言人 林耀珍 2004/03/24

  6. Benefits of Improving Manageability • Development phase • Pinpoint bugs, performance issues • Deployment phase • Configurable, Flexible • Operation phase • Know what is going on in applications and able to manage them. • Provide sufficient information to track down what is going wrong. .NET技術代言人 林耀珍 2004/03/24

  7. Application Management ChallengesFor 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 challenges • Events fired from an application across multiple servers are hard to correlate .NET技術代言人 林耀珍 2004/03/24

  8. Application Management ChallengesFor the Development Organization • No unified instrumentation API • Developers 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 .NET技術代言人 林耀珍 2004/03/24

  9. Configuration Management Application Block- CMAB

  10. App/Web .config • Problems • Simple 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> .NET技術代言人 林耀珍 2004/03/24

  11. Purpose of Configuration Management 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 .NET技術代言人 林耀珍 2004/03/24

  12. Configuration Storage Provider Storage Service Provider Storage Service Provider Data Protection Provider Data Protection Provider Conceptual Design • Pluggable Handler, Storage/protection provider Configuration Manager Caching Service Your Application Application XML Configuration - XML File - SQL Server - Registry - Custom - DPAPI - BCL - Custom Configuration Section Handlers Configuration Section Handlers Configuration Section Handlers Data Protection Provider .NET技術代言人 林耀珍 2004/03/24

  13. CMAB Usage //Read Default section, i.e. first section, HashTable data format configData = ConfigurationManager.Read(sectionName); foreach( string key in configData.Keys ) list.Items.Add( new ListPair( key, configData[ key ] ) ); // Write ConfigurationManager.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> .NET技術代言人 林耀珍 2004/03/24

  14. Handler and Provider • In the app.config / web.config • Define Configuration Section Handler • Define Configuration Storage Provider • Define Data Protection Provider • Define Cache parameters .NET技術代言人 林耀珍 2004/03/24

  15. CMAB 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> .NET技術代言人 林耀珍 2004/03/24

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

  17. .NET Support for Configuration Management <?xml version="1.0" encoding="utf-8" ?> <configuration> <ConfigSections> <section name=“MyConfigSec" type=“MyConfigNS.Handler, MyConfigAssembly”/> </ConfigSections> <MyConfigSec> … </MyConfigSec> </configuration> .NET技術代言人 林耀珍 2004/03/24

  18. Implementation of 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 ); } .NET技術代言人 林耀珍 2004/03/24

  19. Implementation of ConfigurationSectionHandler 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; } } } .NET技術代言人 林耀珍 2004/03/24

  20. Implementation of XmlHashtableSectionHandler 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; } .NET技術代言人 林耀珍 2004/03/24

  21. Implementation of XmlFileStorage 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; } .NET技術代言人 林耀珍 2004/03/24

  22. CMAB 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 .NET技術代言人 林耀珍 2004/03/24

  23. Exception Management Application Block- EMAB

  24. Exception Management Application 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 .NET技術代言人 林耀珍 2004/03/24

  25. Exception Your Application Publisher (event log) Publisher (database) Exception Manager Publisher (text file) Publisher (email) Solution Concept .NET技術代言人 林耀珍 2004/03/24

  26. EMAB Usage • Publishing an exception: • Pluggable ‘Publishers’ of exception info • Event Log as default. try {…}catch (Exception ex){ ExceptionManager.Publish(ex); } .NET技術代言人 林耀珍 2004/03/24

  27. EMAB 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 .NET技術代言人 林耀珍 2004/03/24

  28. EMAB 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> .NET技術代言人 林耀珍 2004/03/24

  29. 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 { ... } .NET技術代言人 林耀珍 2004/03/24

  30. Encounter An Exception • Throw an customized exception • Your 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; .NET技術代言人 林耀珍 2004/03/24

  31. Publish an Exception private 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 ); } } .NET技術代言人 林耀珍 2004/03/24

  32. Tips 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. .NET技術代言人 林耀珍 2004/03/24

  33. Implementation of BaseApplicationException [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; ... } } .NET技術代言人 林耀珍 2004/03/24

  34. Implementation 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); } } .NET技術代言人 林耀珍 2004/03/24

  35. Implementation of DefaultPublisher Get publisher’s source Get custom exception info Get BaseApplicationException info Get stack trace Write to target source .NET技術代言人 林耀珍 2004/03/24

  36. Summary • Register custom event sources by running installutil on your DLL • Understand exception management best practices • Build a ‘dump to text file’ publisher for development .NET技術代言人 林耀珍 2004/03/24

  37. Enterprise Instrumentation FrameworkEIF

  38. EIF Goals • 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 .NET技術代言人 林耀珍 2004/03/24

  39. EIF Core Features • Unified Instrumentation API • Unified model for tracing, eventing, and logging • Leverages WMI Infrastructure (System.Management.Instrumentation) • Structured WMI Event Schema • Manageability contract between developers, quality assurance, and support staff • Configurable At-Source Event Filtering • Fire via WMI, Event Log, Windows Event Trace • Minimal cost for leaving instrumentation in production build • High-speed Diagnostic Tracing • Enables problem management for production applications • Enables tracing user “requests” along application business processes or services .NET技術代言人 林耀珍 2004/03/24

  40. Configuration Event Source Event Source Instrumentation API Event Filtering Event Schema WMI EventTrace EventLog WMISubscriber TraceLog EventLog Trace Reader Single Application Server .NET Application Application Object Application Object Event Sink .NET技術代言人 林耀珍 2004/03/24

  41. Application Server Application Server Distributed .NET Application Event Source Event Source Event Source Event Source Event Routing Event Routing WMI EventTrace EventLog WMI EventTrace EventLog WMISubscriber TraceLog EventLog WMISubscribers TraceLog EventLog TraceReader TraceReader Management Server Management Suite SQL Trace EventRepository Mgmt EventRepository Distributed Servers Event Sink .NET技術代言人 林耀珍 2004/03/24

  42. EIF Usage • Assemblies • Microsoft.EnterpriseInstrumentation • Microsoft.EnterpriseInstrumentation.Schema • System.Configuration.Install • Event sources • Implicit event source (application) TraceMessageEvent.Raise(“something happened"); • Explicit event source .NET技術代言人 林耀珍 2004/03/24

  43. Raise Event by Implicit Event Source using Microsoft.EnterpriseInstrumentation; using Microsoft.EnterpriseInstrumentation.Schema; class MyComponent { // some method public void DoWork() { // Raise an event TraceMessageEvent.Raise(“something happened"); } } .NET技術代言人 林耀珍 2004/03/24

  44. EIF Explicit 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); } } .NET技術代言人 林耀珍 2004/03/24

  45. EIF Configuration Files • Default name • EnterpriseInstrumentation.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 .NET技術代言人 林耀珍 2004/03/24

  46. Event Category Events Event Filter Event Sinks FilterBinding Event Source EIF 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 .NET技術代言人 林耀珍 2004/03/24

  47. EIF Event Schemas • Events in the standard event schema • Administrative events • Audit events • Error events • Trace events • Custom event schemas • Add additional events and change events .NET技術代言人 林耀珍 2004/03/24

  48. Custom 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"; } } .NET技術代言人 林耀珍 2004/03/24

  49. EIF Custom Event Sinks • Writing a custom event sink • Derive 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 .NET技術代言人 林耀珍 2004/03/24

  50. EIF Request Tracing • Enables tracing user requests through a distributed application • Trace business services of the application • Can flow across a distributed .NET application • Tracing is only activated only specific execution path • Events get tagged with request context • Even if no tracing session is enabled .NET技術代言人 林耀珍 2004/03/24

More Related