1 / 37

Enterprise Library Caching Application Block

Enterprise Library Caching Application Block. Scott Densmore Software Design Engineer. Peter Provost Software Design Engineer Ron Jacobs Product Manager. Describe the key logging concepts and capabilities

ekay
Download Presentation

Enterprise Library Caching Application Block

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. Enterprise LibraryCaching Application Block Scott Densmore Software Design Engineer Peter Provost Software Design Engineer Ron JacobsProduct Manager

  2. Describe the key logging concepts and capabilities Describe implementation of logging scenarios using the Logging and Instrumentation Application Block Demonstration Questions Agenda

  3. Sound familiar? • Writing a component to make it simpler to log and trace application information • Different groups in your enterprise writing “new and improved” logging systems • Having multiple logging systems in different layers of the application • A component that logs locally, but doesn’t extend to a distributed logging system • Inflexible configuration options for logging • Recompiling code to change logging behavior

  4. Logging Needs • You need to log business and operations data to various destinations, which are externally configurable • You need to provide tracing to support production debugging • You need to provide auditing for increased security • You need to be able to specify which messages go where, and how they are formatted • You need to be able to log messages to a wide variety of destinations

  5. Logging & Instrumentation Application Block • Provides a simple model for logging events • Replaces the Enterprise Instrumentation Framework and the existing Logging Application Block • Configuration driven – you decide what messages are logged where at runtime. • Sinks provided include • Event Log • Database • Text File • MSMQ • Email • WMI • Create your own…

  6. Scenarios • Populating and raising events from code • Populating a log message with additional context information • Tracing activities and propagating context information • Direct different event types to different sinks • Filter events based on category or priority • Configure logging to be done synchronously or asynchronously • Customize how logging messages are formatted

  7. Populating and raising events Log a message Logger.Write(“Something of note”); How and where logging is done is determined by configuration Convenient overloads allow you to set additional properties Logger.Write(“Something of note”, “DataAccessCategory”); Logger.Write("Something of note", "General", 1, 200, Severity.Information, "Sample Entry");

  8. Log Entries • The application block constructs a log entry to hold the information • Every log entry has the following properties • Message (required) • Category (default determined by configuration) • Priority (default -1) • Event ID (default 1) • Severity (default Severity.Unspecified) • Title (default “”) • You can create (and reuse) a log entry object, and pass it to the Logger.Write method

  9. Creating Log Entries The application block creates the log entry Logger.Write(“Something of note”); The client code creates the log entry LogEntry log = new LogEntry(); log.Message = "My message"; log.EventId = 1; log.Category = "UI Events"; log.Priority = 2; log.Severity = Severity.Information; log.Title = "My title"; Logger.Write(log);

  10. Example Output – Event Log

  11. Example Output – Flat File

  12. Populating a Log Message with Additional Context Information You can pass a dictionary of name-value pairs to the application block Hashtable customProperties = new Hashtable(); customProperties["key1"] = "value1"; customProperties["key2"] = "value2"; customProperties["key3"] = "value3"; Logger.Write("Something of note", "General", 1, 200, Severity.Information, "Sample Entry", customProperties); Output (Text Formatter)

  13. Extra Information Providers DebugInformationProvider example Hashtable dictionary = new Hashtable(); DebugInformationProvider informationHelper; informationHelper = new DebugInformationProvider(); informationHelper.PopulateDictionary(dictionary); Logger.Write("Log entry with extra information", dictionary); Output (includes stack trace)

  14. Tracing Activities and Propagating Context Tracing an application activity is a common task The application block provides support to track an activity by an activity identifier The activity identifier can be specified in the code, or generated by the application block Components inherit the caller’s activity id and log category A component that is called as part of an activity can temporarily override the activity identifier (nested activities) or category The application block automatically logs the start and end time of the activity

  15. Tracing Activities and Propagating Context

  16. Tracing Example Activity tracing is provided by the Tracer class // Begin tracing activity using (new Tracer("UI Events")) { DoDataAccess(); } private void DoDataAccess() { // Trace nested activity using (new Tracer("Data Access Events“, “Data Access”)) { Logger.Write(“Troubleshooting message"); } }

  17. Tracing Example Output Activity d9adc4bd-8883-4014-9696-e43d23f95201 Activity Data Access

  18. Directing Different Event Types to Different Sinks Every log entry specifies a category (either explicitly in the code, or by inheriting the configured default) The application block examines the category to determine where to send the log entry (the destination) A destination specifies a formatter and a sink Categories and sinks are controlled through configuration Sinks shipped with application block: email, event log, flat file, MSMQ, WMI (ETW coming soon!)

  19. Directing Different Event Types to Different Sinks The Configuration Console is used to create categories and destinations

  20. Directing Different Event Types to Different Sinks The default category is determined by a property of the Distributor Settings Messages that do not specify a category, or specify an unrecognized category, will assigned the default

  21. Filter Events Based on Category or Priority Filtering occurs before a log entry is delivered to the distribution strategy Each message has a priority (either set explicitly through code or the inherited default, -1) You can configure the Client Settings to cause messages below a specified priority to be filtered out You can configure the Client Settings to only log messages of a specified category You can configure the Client Settings to filter out log messages of a specified category

  22. Filter Events Based on Category or Priority In the following example, messages of priority 0 or 1 will not be logged

  23. Filter Events Based on Category or Priority The CategoryFilterSettings property of the Client Settings determines if categories are logged or filtered out In the following example, messages for category UI Events are not logged

  24. Configure Logging to be Done Synchronously or Asynchronously The client settings determine the distribution strategy Synchronous logging is performed in the process of the client Asynchronous logging is implemented using Microsoft Message Queuing (MSMQ) For asynchronous logging, an application block Windows Service pulls log entries off of the queue and sends them to the application block You can extend the application block and provide a custom distribution strategy

  25. Configure Logging to be Done Synchronously or Asynchronously

  26. Configure Logging to be Done Synchronously or Asynchronously The client settings determine the distribution strategy All messages for a client use the same strategy

  27. Configure Logging to be Done Synchronously or Asynchronously For asynchronous logging, the MSMQ distribution strategy includes a property for the queue name

  28. Configure Logging to be Done Synchronously or Asynchronously The MSMQ Distributor Service must be configured with the appropriate queue name (must match the client) Using the Configuration Console, open the file MsmqDistributor.exe.config Add the MSMQ Distributor Service to the Distributor Settings Set the MsmqPath property to match the client’s queue name

  29. Customize How Logging Messages are Formatted Formatters accept a log entry and return a formatted string The application block sends the formatted string to the sink The Text Formatter uses a template to produce the formatted string You can have multiple Text Formatters in your application configuration, each with a custom template You can write a custom formatter

  30. Customize How Logging Messages are Formatted Log entries are routed to a destination based upon their category The destination specifies the formatter to use and the sink which will receive the formatted log entry

  31. Customize How Logging Messages are Formatted The Text Formatter exposes the template through a configuration property

  32. Customize How Logging Messages are Formatted The Template Editor allows you to easily change how the log entry is formatted Tokens are substituted with log entry values

  33. View/Application Share: Demonstration • [Live Meeting View/Application Share. Use Live Meeting > Edit Slide Properties... to edit.]

  34. Enterprise Library v1 Caching Exceptions Legend Security Data Access Logging Dependency Plug-in Crypto Configuration Config Tool

  35. Announcing: Enterprise Library 1.0 Download it Today! http://www.microsoft.com/practices

  36. patterns & practices Live! • 3/17 Enterprise Library Exception Handling Application Block • 3/22 Enterprise Library Cryptography Application Block • 3/24 Enterprise Library Security Application Block • 3/28 Building your own block • 3/31 Enterprise Library Applied http://www.pnplive.com

  37. http://www.microsoft.com/practicesEnterprise Library Communityhttp://go.microsoft.com/fwlink/?linkid=39209&clcid=0x09

More Related