Table of Contents

Property Writer

Namespace
GeometryHelper
Assembly
GeometryHelper.dll

Writer

Gets or sets what receives each message: its level, its text and the exception behind it, if any. Null, the default, writes Format(GeometryHelperLogLevel, string, Exception) of the message to Trace.

public static Action<GeometryHelperLogLevel, string, Exception> Writer { get; set; }

Property Value

Action<GeometryHelperLogLevel, string, Exception>

Examples

On the console of a console application:

GeometryHelperLog.Writer = (level, message, exception) =>
    Console.WriteLine(GeometryHelperLog.Format(level, message, exception));

GeometryHelperLog.Info("Started.");   // prints: INFO Started.

On the status bar of Tekla Structures (using Tekla.Structures.Model.Operations; and using GeometryHelper.Enums;). The bar shows one line at a time, the last one written, so Debug detail is left out and the summary each conversion ends with stays on the bar:

GeometryHelperLog.Writer = (level, message, exception) =>
{
    if (level >= GeometryHelperLogLevel.Info)
    {
        Operation.DisplayPrompt(GeometryHelperLog.Format(level, message, exception));
    }
};

Every message in a file:

GeometryHelperLog.Writer = (level, message, exception) =>
    File.AppendAllText(logPath, GeometryHelperLog.Format(level, message, exception) + Environment.NewLine);

Remarks

It is called one message at a time, even when the messages come from work done on several threads at once — a clash check, the products of an IFC file — so a writer need not be safe to call from two at once. It is called on those threads, though: a writer showing messages on a form hands them over with BeginInvoke, since Invoke waits for the form's thread, which may be waiting for that very work.