Table of Contents

Interface ICodeLog

Namespace
ToSic.Sxc.Code
Assembly
ToSic.Sxc.dll

A special logger for dynamic code (Razor, WebApi). It is always available to add messages to insights.

[PublicApi]
public interface ICodeLog

Remarks

Added in v15, replaces the then removed ILog interface.

Properties

Preserve

Determines if this log should be preserved in the short term. Like for live-analytics / live-insights. Default is true.

In scenarios like search-indexing it will default to false. You can then do Log.Preserve = true; to temporarily activate it while debugging.

bool Preserve { get; set; }

Property Value

bool

Methods

Add(string, string, string, int)

Add a message log entry

string Add(string message, string cPath = null, string cName = null, int cLine = 0)

Parameters

message string

Message to log

cPath string

auto pre filled by the compiler - the path to the code file

cName string

auto pre filled by the compiler - the method name

cLine int

auto pre filled by the compiler - the code line

Returns

string

Call(string, string, bool, string, string, int)

Add a log entry for method call, returning a method to call when done

Action<string> Call(string parameters = null, string message = null, bool useTimer = false, string cPath = null, string cName = null, int cLine = 0)

Parameters

parameters string

what was passed to the call in the brackets

message string

the message to log

useTimer bool

enable a timer from call/close

cPath string

auto pre filled by the compiler - the path to the code file

cName string

auto pre filled by the compiler - the method name

cLine int

auto pre filled by the compiler - the code line

Returns

Action<string>

Call<T>(string, string, bool, string, string, int)

Add a log entry for method call, returning a method to call when done

Func<T, string, T> Call<T>(string parameters = null, string message = null, bool useTimer = false, string cPath = null, string cName = null, int cLine = 0)

Parameters

parameters string

what was passed to the call in the brackets

message string

the message to log

useTimer bool

enable a timer from call/close

cPath string

auto pre filled by the compiler - the path to the code file

cName string

auto pre filled by the compiler - the method name

cLine int

auto pre filled by the compiler - the code line

Returns

Func<T, string, T>

Type Parameters

T

Remarks

Not used much, but major change in V15 - the first value in the result is the data, the second is the string to log. Before in the ILog it was (message, data), new is (data, message)

Exception(Exception, string, string, int)

Add an exception as special log entry

void Exception(Exception ex, string cPath = null, string cName = null, int cLine = 0)

Parameters

ex Exception

The Exception object

cPath string

auto pre filled by the compiler - the path to the code file

cName string

auto pre filled by the compiler - the method name

cLine int

auto pre filled by the compiler - the code line

Warn(string, string, string, int)

Add a warning log entry

void Warn(string message, string cPath = null, string cName = null, int cLine = 0)

Parameters

message string
cPath string

auto pre filled by the compiler - the path to the code file

cName string

auto pre filled by the compiler - the method name

cLine int

auto pre filled by the compiler - the code line