Browse documentation

Class FileLog

Namespace
HarmonyLib
Assembly
0Harmony.dll

A file log for debugging

public static class FileLog
Inheritance
object
FileLog

Fields

indentChar

The indent character. The default is tab

public static char indentChar

Field Value

char

indentLevel

The current indent level

public static int indentLevel

Field Value

int

Properties

LogPath

Full pathname of the log file, defaults to a file called harmony.log.txt on your Desktop

public static string LogPath { get; }

Property Value

string

LogWriter

Set this to make Harmony write its log content to this stream

public static StreamWriter LogWriter { get; set; }

Property Value

StreamWriter

Methods

ChangeIndent(int)

Changes the indentation level

public static void ChangeIndent(int delta)

Parameters

delta int

The value to add to the indentation level

Debug(string)

Log a string directly to disk if Harmony.DEBUG is true. Slower method that prevents missing information in case of a crash

public static void Debug(string str)

Parameters

str string

The string to log.

FlushBuffer()

Flushes the log buffer to disk (use in combination with LogBuffered)

public static void FlushBuffer()

GetBuffer(bool)

Returns the log buffer and optionally empties it

public static List<string> GetBuffer(bool clear)

Parameters

clear bool

True to empty the buffer

Returns

List<string>

The buffer.

Log(string)

Logs a string directly to disk to avoid losing information in case of a crash

public static void Log(string str)

Parameters

str string

The string to log.

LogBuffered(List<string>)

Logs a list of string in a buffered way. Use this method only if you are sure that FlushBuffer will be called or else logging information is incomplete in case of a crash

public static void LogBuffered(List<string> strings)

Parameters

strings List<string>

A list of strings to log (they will not be re-indented)

LogBuffered(string)

Log a string in a buffered way. Use this method only if you are sure that FlushBuffer will be called or else logging information is incomplete in case of a crash

public static void LogBuffered(string str)

Parameters

str string

The string to log

LogBytes(long, int)

Logs some bytes as hex values

public static void LogBytes(long ptr, int len)

Parameters

ptr long

The pointer to some memory

len int

The length of bytes to log

LogIL(int, Label)

Logs the intermediate language (IL) code at the specified position with the given label operand

public static void LogIL(int codePos, Label label)

Parameters

codePos int

The position in the IL code to log.

label Label

The label operand associated with the IL code to log.

Remarks

Formats and logs the IL code position and label operand for detailed IL tracking or debugging.

LogIL(int, OpCode)

Logs the specified Intermediate Language (IL) operation code and its position in the code stream

public static void LogIL(int codePos, OpCode opcode)

Parameters

codePos int

The position of the IL operation code in the code stream.

opcode OpCode

The IL operation code to log.

Remarks

This method formats the IL operation code and its position into a string and logs it.

LogIL(int, OpCode, object)

Logs information about an Intermediate Language (IL) instruction, including its position, opcode, and operand

public static void LogIL(int codePos, OpCode opcode, object arg)

Parameters

codePos int

The position of the IL instruction within the method body.

opcode OpCode

The System.Reflection.Emit.OpCode representing the operation to be performed.

arg object

The operand associated with the IL instruction, or null if the instruction has no operand.

Remarks

This method formats and logs details about an IL instruction for debugging or analysis purposes. The logged output includes the instruction's position, opcode, and operand (if any).

LogILBlockBegin(int, ExceptionBlock)

Logs the beginning of an intermediate language (IL) exception handling block

public static void LogILBlockBegin(int codePos, ExceptionBlock block)

Parameters

codePos int

The position of the IL code where the block begins.

block ExceptionBlock

The ExceptionBlock representing the type of exception handling block to log. This includes information about the block type (e.g., try, catch, finally) and any associated metadata.

Remarks

Logs the start of an exception handling block (e.g., .try, .catch, .finally, .fault), adjusts indentation, and simulates a LEAVE opcode for consistency.

LogILBlockEnd(int, ExceptionBlock)

Logs the end of an intermediate language (IL) exception block

public static void LogILBlockEnd(int codePos, ExceptionBlock block)

Parameters

codePos int

The position in the IL code where the block ends.

block ExceptionBlock

The exception block to log. Must have a valid block type.

Remarks

This method handles the logging of specific types of exception blocks, such as the end of a try-catch or similar constructs. It adjusts the indentation level and outputs relevant information about the block's conclusion.

LogILComment(int, string)

Logs an inline comment at the specified code position

public static void LogILComment(int codePos, string comment)

Parameters

codePos int

The position in the code where the comment should be logged.

comment string

The comment text to log. Cannot be null or empty.

Remarks

This method formats the comment with the code position and logs it.

Reset()

Resets and deletes the log

public static void Reset()

SetBuffer(List<string>)

Replaces the buffer with new lines

public static void SetBuffer(List<string> buffer)

Parameters

buffer List<string>

The lines to store

Harmony 3 preview

For the stable release, read the 2.x documentation.