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
  1. Integrations

Log4net integration

PreviousSerilog integrationNextMicrosoft logging integration

Last updated 6 years ago

Location: module.

var log4netAdapter = new Log4netLog(log4netLogger);

Log4netLog is an adapter that wraps an arbitrary instance of Log4net's ILogger and implements Vostok . It enables gradual migration for Log4net users by allowing existing code to be ported to Vostok ILog abstraction without immediately changing and reconfiguring underlying implementation.

Log4netLog prerenders messages into text as Log4net library does not support all the syntax capabilities of Vostok . Properties are passed as-is.

ForContext method implementation differs from common conventions described in section. It translates source context values into logger names by using a configurable LoggerNameFactory delegate. Having determined the new logger name, it returns a copy of the log with underyling ILogger obtained from current ILogger's repository by this name.

Default behaviour of LoggerNameFactory is to merge context values using dot as separator:

["foo", "bar", "baz"] context --> "foo.bar.baz" logger name

Here's how to configure it to use only the last value from source context:

log.LoggerNameFactory = context => context.Last();
log4net
log interface
message templates
source context