• Lexical
Show / Hide Table of Contents
  • Lexical.FileSystem
    • Introduction
    • Abstractions
      • IFileSystem
        • IFileSystem
        • IFileSystemBrowse
        • IFileSystemCreateDirectory
        • IFileSystemDelete
        • IFileSystemFileAttribute
        • IFileSystemMount
        • IFileSystemMove
        • IFileSystemObserve
        • IFileSystemOpen
      • IEvent
      • IEntry
      • IOption
      • IToken
    • FileSystem
    • VirtualFileSystem
    • MemoryFileSystem
    • EmbeddedFileSystem
    • HttpFileSystem
    • Decoration
    • IFileProvider
    • Utility
      • DisposeList
      • FileScanner
      • VisitTree
      • File Operation
  • Lexical.FileProvider
    • Introduction
    • Package
    • Package.Abstractions
    • Root
    • Zip
    • Dll
    • SharpCompress
    • SharpZipLib
    • FileScanner
    • Utils
  • Lexical.Localization
    • Introduction
    • Tutorial
    • Asset
      • IAsset
      • IStringAsset
    • Line
      • ILine
      • ILineFactory
      • ILineRoot
      • ILineFormat
      • ILineLogger
      • LineComparer
    • File
      • ILineReader
      • ILineWriter
      • Ini
      • Json
      • Xml
      • Resx
      • Resources
    • Miscellaneous
      • Plurality
      • ICulturePolicy
      • IStringFormat
      • Dependency Injection
    • Practices
      • Class Library
      • Class Library DI
      • Class Library DI opt.
  • Lexical.Utilities
    • Introduction
    • UnicodeString
    • FileScanner
    • Permutation
    • Tuples
    • StructList

ILineLogger

Lexical.Localization.Common.ILogger is the root interface for loggers.

namespace Lexical.Localization.Common
{
    /// <summary>
    /// Localization logger.
    /// 
    /// See sub-interfaces
    /// <list type="bullet">
    ///     <item><see cref="Lexical.Localization.StringFormat.IStringResolverLogger"/></item>
    ///     <item><see cref="Lexical.Localization.Resource.IResourceResolverLogger"/></item>
    /// </list>
    /// </summary>
    public interface ILogger
    {
    }
}

namespace Lexical.Localization.StringFormat
{
    /// <summary>
    /// Logger that logs string resolving of <see cref="IStringResolver"/>.
    /// </summary>
    public interface IStringResolverLogger : Lexical.Localization.Common.ILogger, IObserver<LineString>
    {
    }
}

namespace Lexical.Localization.Resource
{
    /// <summary>
    /// Logger that logs resource resolving of <see cref="IResourceResolver"/>.
    /// </summary>
    public interface IResourceResolverLogger : Lexical.Localization.Common.ILogger, IObserver<LineResourceBytes>, IObserver<LineResourceStream>
    {
    }
}


LineStatusSeverity has four severity levels.

Level Description
Ok OK value.
Warning Warning, but produced a value.
Error Error occured, but produced a fallback value.
Failed Failed, no value.

If LineStatusSeverity.OK is used, then every result is logged. If LineStatusSeverity.Failed then, only when no result could be produced.

TextWriter

Logger can output to TextWriter such as Console.Out.

ILine root = LineRoot.Global.Logger(Console.Out, LineStatusSeverity.Ok);

Resolving a string causes logger to print the resolved result.

Console.WriteLine(root.Type("MyClass").Key("OK").Text("OK"));

The logger output.

ResolveOkFromKey|CultureOkMatchedNoCulture|PluralityOkNotUsed|StringFormatOkString Type:MyClass:Key:OK = "OK"

Diagnostics Trace

Logger can output to System.Diagnostics.Trace.

Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));
ILine root = LineRoot.Global.DiagnosticsTrace(LineStatusSeverity.Ok);

Resolving a string causes the logger to print the resolved result.

Console.WriteLine(root.Type("MyClass").Key("OK").Text("OK"));

The logger output.

docs Information: 0 : ResolveOkFromKey|CultureOkMatchedNoCulture|PluralityOkNotUsed|StringFormatOkString Type:MyClass:Key:OK = "OK"

ILogger

.ILogger(ILoggerFactory) appends Microsoft.Extensions.Logger.ILoggerFactory to a line. This forwards the Type from the line to logger.

LoggerFactory loggerFactory = new LoggerFactory();
loggerFactory.AddConsole(LogLevel.Trace);
ILine root = LineRoot.Global.ILogger(loggerFactory);

.ILogger(ILogger) appends Microsoft.Extensions.Logger.ILogger to a line.

LoggerFactory loggerFactory = new LoggerFactory();
loggerFactory.AddConsole(LogLevel.Trace);
ILogger logger = loggerFactory.CreateLogger("MyClass");
ILine root = LineRoot.Global.ILogger(logger);

Resolving a string causes logger to print the resolved result.

Console.WriteLine(root.Type("MyClass").Key("OK").Text("OK"));

The logger output.

info: MyClass[0]
ResolveOkFromKey | CultureOkMatchedNoCulture | PluralityOkNotUsed | StringFormatOkString Type: MyClass: Key: OK = "OK"

NLog

.NLog(NLog.LoggerFactory) appends NLog.LoggerFactory to a line. This forwards the Type from the line to logger.

ILine root = LineRoot.Global.NLog(NLog.LogManager.LogFactory);

.NLog(NLog.ILogger) appends NLog.ILogger to a line.

NLog.ILogger nlog = NLog.LogManager.GetLogger("MyClass");
ILine root = LineRoot.Global.NLog(nlog);

Resolving a string causes logger to print the resolved result.

Console.WriteLine(root.Type("MyClass").Key("OK").Text("OK"));

The logger output.

2019-06-08 14:10:46.4939|INFO|MyClass|ResolveOkFromKey|CultureOkMatchedNoCulture|PluralityOkNotUsed|StringFormatOkString Type:MyClass:Key:OK = "OK"
OK

LineRoot

The deploying application can place a logger into LineRoot.

(LineRoot.Global as LineRoot.Mutable).Logger = new LineTextLogger(Console.Out, LineStatusSeverity.Ok);

Any line that is derived from LineRoot causes logger to be applied.

Console.WriteLine(LineRoot.Global.Type("MyClass").Key("OK").Text("OK"));
Back to top Copyright © 2015-2020 Toni Kalajainen