Partager via


Logging events to a disk file

patterns & practices Developer Center

This scenario is one of several that describe the typical requirements for using the Semantic Logging Application Block in your applications. It describes the process for setting up the block to send log events to a disk file.

Typical Goals

You need to send logging information created as log entries to one or more sinks or targets, and the list of targets includes a disk file. You want to set up the Semantic Logging Application Block to use a suitable event sink, decide what type of file to create (text, JSON, or XML), and configure the format and other file logging options you require.

Notes

The major difference between the two types for event sink you can use for storing events in flat files is that the Rolling Flat File event sink allows you to start a new log file at specified intervals.

You should not configure more than one Flat File sink or Rolling Flat File sink instance to write to the same physical file. However, you can enable the same listener (and sink) on multiple event sources and funnel the events from those multiple event sources to the same file.

If you use the XmlEventTextFormatter class to write the log entries as XML, the formatter class writes the log entries to comply with the schema described in the Event Schema topic on MSDN. Tools such as PerfView can load XML files that use this schema.

Solution

The following steps describe the process, and provide links to more details for each step.

To configure logging to a disk file

  1. Define an event source for your application. For more information, see the topic Developing event sources using the .NET EventSource class.
  2. Write code to raise the events you defined in response to actions within the application. For more information, see the topic Raising events from your applications.
  3. Decide if you will use the in-process or out-of-process approach for collecting events. For more information to help you decide, see the topic Overview of logging using the Semantic Logging Application Block.
  4. If you choose to use the in-process approach:
  5. If you choose to use the out-of-process approach:

Next Topic | Previous Topic | Home | Community