Skip to content
Minimal interface (no GC pressure, no stack walk, no custom enums,no formatting) log facade
C# F# Shell
Find file
New pull request
Fetching latest commit...
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Log Facade

All comments are in src/CommonLogFacade/System/Diagnostics/CommonLogFacadeAll.cs

namespace System.Diagnostics
    public partial interface ISourceSwitch
        SourceLevels Level { get; }

    public partial interface ILogFacade:ISourceSwitch
        void Log(string message, TraceEventType severity);

    public partial interface IModuleLogFacade:ISourceSwitch
        void Log(string message, TraceEventType severity,string source);

    public static class ILogFacadeLevelExtensions
        public static bool ShouldLog(this ISourceSwitch current, SourceLevels  compared){
            return ((int)compared & (int)current.Level) == (int)compared ;
        public static bool ShouldLog(this ISourceSwitch current, TraceEventType  compared){
           return ((int)compared & (int)current.Level) == (int)compared ;

Layers (from high level to infrastucture)

  1. User code

  2. MyFancySugarConvenienceLayer: Warn(..), LogError(..), IfDebugEnabled, IfInfoEnabled, exception to string converter, string/args format, reflection of passed arguments, custom formatters, semantic interfaces(strongly typed write method for each event)

  3. This Facade (ILogFacade or IModuleLogFacade). Interface language known by all subsystems. ILogFacade should be injected into high cohesive small components. IModuleLogFacade should be provided to bigger parts with several related functionals.

  4. Real robust logging with : log entry headers (process, thread, timestamp, ...), configuration, cleanup, storage destinations, asynchrony, etc. . E.g. EntLib, System.Diagnostics, log4net

Approximate sizes

System more then Module. Module more then Component.

|      Module
|      -----------------------
|      |      Component
|      |      Component
|      Module
|      -----------------------
|      |      Component
|      |      Component


  • .NET APIs organization design

  • Minimalistic interface. Few methods to implement.

  • Sits in middle of layered design with optional feature reuse (abstraction, convenience classes, formatting, underlying implementation)

  • Not directly usable. You write sugar wrapper and provide implementation to use in your code. Read tests/CommonLogFacade.Tests/CommonLogFacadeTests.cs

  • Location info (function name, etc. ) is obtained behind facade via stack walks or before facade(as part entry message formatting)

  • Stack walks are not part of API and not enforced to work on all platforms and preventing slowness. You can do walks behind interface if so needed (like in .NET tracing).

  • Allows no object creation if entry will not be written to prevent allocation and GC

  • String message is passed. No standardized formatting. All fancy entry message formatting is done by you code before calling facade. E.g. creating YAML string out of format string, exception and bunch of numbers.

  • Log facade implementation responsible to add location info(thread,process, etc) and log entry header into (timestamp,etc.) behind facade.

  • Log facade implementation can be any logging available (EntLib, System.Diagnostics, log4net, etc.)

  • No exceptions in API (what should be done with this? stack obtained? just message?).

  • You need static singleton log or factory. You do static singleton log or factory.

  • No very specific .NET types in API, e.g. expression or delegate. Allow for COM/WinRT interop.

  • No fancy short methods names with formatting - no guessing to satisfy all needs. To much to implement for facade. To easy to break.

  • No numeric event ids which require human log reader to search meaning somewhere else.

  • No specific enforced message formatting. If you need this - use specific logging library or write your own facade.

  • Usage of semantics and enumeration of System.Diagnostics instead of inventing own. Putting classes into same namespace to reduce namespaces number (like WPF TraceSources).

  • Hierarchy of logs can be made via wrapping IModuleLogFacade into other and adding grouping prefix to source. E.g. "Data.RealTime" into "MyCompany.Data.RealTime".

  • Hierarchy of SourceLevels to shut up noisy components:)


Developed with SharpDevelop 4.x.

Releasaed via build.cmd using FAKE.

If conflicts

  • Add alias to CommonLogFacade assembly, e.g. common and then:
extern alias common;
using ILogFacade = common::System.Diagnostics.ILogFacade;
  • Copy and paste it into you code.
  • il-repack into you logging library


  • ISystemLogFacade: more versatile to routing and filtering, several sources, priority, event id, may be runtime reconfiguration
  • add Code Contracts to interfaces

Logging design links

Common design links

Something went wrong with that request. Please try again.