Presentation is loading. Please wait.

Presentation is loading. Please wait.

Enterprise Library Caching Application Block Peter Provost Software Design Engineer Ron Jacobs Product Manager Scott Densmore Software Design Engineer.

Similar presentations


Presentation on theme: "Enterprise Library Caching Application Block Peter Provost Software Design Engineer Ron Jacobs Product Manager Scott Densmore Software Design Engineer."— Presentation transcript:

1 Enterprise Library Caching Application Block Peter Provost Software Design Engineer Ron Jacobs Product Manager Scott Densmore Software Design Engineer

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

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 EmailWMI 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 Log a message Populating and raising events 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 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 Log Entries

9 The application block creates the log entry Creating Log Entries 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); Logger.Write(“Something of note”); The client code creates the log entry

10 Example Output – Event Log

11 Example Output – Flat File

12 You can pass a dictionary of name-value pairs to the application block Populating a Log Message with Additional Context Information Output (Text Formatter) 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);

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

14 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 Tracing Activities and Propagating Context

15

16 Tracing Example // 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"); } Activity tracing is provided by the Tracer class

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

18 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!) Directing Different Event Types to Different Sinks

19 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 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 Configure Logging to be Done Synchronously or Asynchronously

25

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

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

28 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 Configure Logging to be Done Synchronously or Asynchronously 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 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 Customize How Logging Messages are Formatted

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

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

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

34 Security Crypto Configuration DataAccessLogging CachingExceptions Enterprise Library v1 Legend Dependency Plug-in ConfigTool

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

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/practices http://www.microsoft.com/practices Enterprise Library Community http://go.microsoft.com/fwlink/?linkid=39209&clcid=0x09 http://go.microsoft.com/fwlink/?linkid=39209&clcid=0x09 http://www.microsoft.com/practices http://go.microsoft.com/fwlink/?linkid=39209&clcid=0x09


Download ppt "Enterprise Library Caching Application Block Peter Provost Software Design Engineer Ron Jacobs Product Manager Scott Densmore Software Design Engineer."

Similar presentations


Ads by Google