Class ServerLogFile
- Namespace
- Unity.Multiplayer.Core
The server's log file in the package's Logs/ folder: one file per run, named
server-yyyyMMdd-HHmmss.log (UTC), each line 2026-10-20T12:00:00.000Z [Info] message. Opening one
deletes the oldest runs beyond the number kept. Thread-safe.
public sealed class ServerLogFile : IDisposable
- Inheritance
-
ServerLogFile
- Implements
- Inherited Members
Fields
FileExtension
Every log file's extension.
public const string FileExtension = ".log"
Field Value
FilePrefix
Every log file's name starts with this.
public const string FilePrefix = "server-"
Field Value
Properties
Path
The file's full path.
public string Path { get; }
Property Value
Methods
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
FormatLine(DateTime, string, string)
One formatted line, without the newline.
public static string FormatLine(DateTime timeUtc, string level, string message)
Parameters
Returns
List(string)
The log files in directory, oldest first: by last-write time, then by the run their name
stands for (its timestamp, then its same-second suffix, the unsuffixed file being the first of that second).
Names alone mis-order same-second runs ("-2" sorts before the unsuffixed file, "-10" before "-2"), and a
clock that went back would mis-order them too (UM-T88).
public static IReadOnlyList<string> List(string directory)
Parameters
directorystring
Returns
Open(string, DateTime, int)
Creates directory if needed, deletes the oldest log files so that, with the new one,
at most keep remain (0 keeps all), and opens a new file named for nowUtc.
public static ServerLogFile Open(string directory, DateTime nowUtc, int keep)
Parameters
Returns
Exceptions
- ArgumentException
directoryis empty orkeepis negative.
Prune(string, int)
Deletes the oldest log files until at most keep remain. Returns the deleted paths.
public static IReadOnlyList<string> Prune(string directory, int keep)
Parameters
Returns
Write(DateTime, string, string)
Appends one line. Does nothing after Dispose().
public void Write(DateTime timeUtc, string level, string message)