Compartilhar via


Choosing and using event sinks

patterns & practices Developer Center

The Semantic Logging Application Block includes sinks that enable you to write log messages to the Console, and save log messages to a database, a Microsoft Azure storage table, and to flat files. The choice of which sinks to use depends on how you plan to analyze and monitor the information you are collecting. For example, if you save your log messages to a database you can use SQL queries to analyze and export the data.

The following event sinks are available as part of the Semantic Logging Application Block:

  • Console event sink. This event sink writes formatted log entries to the console.
  • Flat File event sink. This event sink writes log entries to a text file.
  • Rolling Flat File event sink. This event sink writes log entries to a text file and creates a new log file depending on the current log file age and/or size.
  • SQL Database event sink. This event sink writes log entries to a SQL Server or Azure SQL Database database. By default, the sink buffers the log messages.
  • Azure Table Storage event sink. This event sink writes log entries to Azure table storage. By default, the sink buffers the log messages.

When choosing the sinks to use in your logging implementation, you should base the decision on operational needs rather than developmental or perceived requirements. Typically, developers will liaise with administrators to choose the logging destinations best suited to the application deployment, monitoring, and usage scenario.

When using the Semantic Logging Application Block in-process, the developer must change the code in the application to change the logging strategy, which will result in downtime and consequent redeployment effort. When using the Out-of-Process Host, administrators can change the logging strategy without requiring the application to be restarted.

Also, keep in mind that single-row-based text formats may not be the best choice for storing or exporting your entries because the messages and the payload items could span several lines. When using text file logging destinations, consider if JSON or XML formats may be a better choice. These can be created by using the appropriate event formatter with your choice of text file sink. For information about event formatters, see Choosing and using text formatters.

You can obtain additional event sinks created by third parties from NuGet, such as sinks that store log messages in ElasticSearch and Splunk. You can also create your own custom event sinks. For more details, see Creating a custom event sink.

Next Topic | Previous Topic | Home | Community