Logging events to the Console
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 using the block to send log events to the console.
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 console window. You want to set up the Semantic Logging Application Block to use a suitable event sink and format the log entries.
Notes
The console event sink is not recommended for use in high-throughput or production scenarios. Typically, you will use it only during development and testing of your event logging strategy.
Solution
The following steps describe the process, and provide links to more details for each step.
To configure logging to the console
- Define an event source for your application. For more information, see the topic Developing event sources using the .NET EventSource class.
- 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.
- 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.
- If you choose to use the in-process approach:
- Use NuGet to add the Semantic Logging Application Block package to your Visual Studio project. For more information, see the topic Using the block in applications for the in-process scenario.
- Add code to configure the Console sink. You can use a color mapper that automatically colors log messages based on severity, and specify a formatter for the output. For more information, see the topics Choosing and using event sinks and Choosing and using text formatters
- If you choose to use the out-of-process approach:
- Install the Out-of-Process Host service application. For more information, see the topic Installing and running the Out-of-Process Windows Service/Console Host.
- Configure the Out-of-Process Host to use the Console event sink. You can use a color mapper that automatically colors log messages based on severity, and specify a formatter for the output. For more information, see the topics Using the trace event service for the out-of-process scenario, Choosing and using event sinks, and Choosing and using text formatters