Vostok.Logging
HomeQuickstartModulesImplementations
1.0.0
1.0.0
  • Home
  • Quickstart
  • Guarantees
  • Configuration
  • Concepts and basics
    • Log interface
    • Log events
    • Syntax
      • Logging extensions
      • Message templates
      • Providing property values
    • Formatting
      • Output templates
      • Special properties
      • Format specifiers
    • Source context
    • Operation context
  • Modules
    • Abstractions
    • Configuration
    • Formatting
    • Console
    • File
    • Hercules
    • Context
    • Serilog
    • Log4net
    • NUnit
    • Microsoft
  • Implementations
    • Silent log
    • Console log
    • File log
    • Hercules log
  • Integrations
    • Serilog integration
    • Log4net integration
    • Microsoft logging integration
  • How-to guides
    • Using operation context
    • Using static log provider
    • Filtering events
    • Enriching events
    • Transforming events
    • Combining multiple logs
    • Custom output templates
    • External configuration rules
Powered by GitBook
On this page
  • Constructing custom templates
  • Passing to a log instance
  1. How-to guides

Custom output templates

Prerequisites: install formatting module, use one of text-based logs (console or file).

Constructing custom templates

There are two ways to obtain a custom template:

  • Parse it from an arbitrary string:

    • var template = OutputTemplate.Parse("Here's the message: {Message}{NewLine}");
  • Use OutputTemplateBuilder to construct it in code:

    • var template = new OutputTemplateBuilder()
          .AddText("Here's the message: ")
          .AddMessage()
          .AddNewline()
          .Build();

Passing to a log instance

Custom output templates can be passed to text-based logs as parameters in their respective settings:

var log = new ConsoleLog(new ConsoleLogSettings
{
    OutputTemplate = customTemplate
});
var log = new FileLog(new FileLogSettings
{
    OutputTemplate = customTemplate
});
PreviousCombining multiple logsNextExternal configuration rules

Last updated 6 years ago