High-performance logging extension package for Unity. Built on ZLogger, it provides XLog* extension methods and uses scripting define symbols to completely remove log calls from the build.
ZLogger is widely used for its compiler-transformed interpolated strings and standard ILogger integration. It does not, however, offer stripping log call code from distribution builds; this package fills that role.
- Unity 2022.3+ (12f1)
- ZLogger, ZLogger.Unity 2.5+
- xpTURN.Polyfill 0.3.0+ (required for C# 10/11 features, or configure manually)
How to add xpTURN.Polyfill to your project (when not installed or configured)
To use XLogger (including ZLogger), you need to modify the project settings to use the C# preview language version (e.g. -langversion:preview, adding Polyfill code).
⚠️ There can be various ways to set this up. You can skip this section if you have already added it to your project.
- Open Window > Package Manager
- Click + > Add package from git URL...
https://github.com/xpTURN/Polyfill.git?path=src/Polyfill/Assets/Polyfill
- ⚙️ Run Edit > Polyfill > Player Settings >
Apply Additional Compiler Arguments -langversion (All Installed Platforms)
How to add ZLogger to your project (when not installed)
- Open Window > Package Manager
- Click + > Add package from git URL...
https://github.com/GlitchEnzo/NuGetForUnity.git?path=/src/NuGetForUnity
- Open NuGet > Manage NuGet Packages
- Click 🔍️, enter ZLogger, then click Search
- Find ZLogger by Cysharp and click Install
- Open Window > Package Manager
- Click + > Add package from git URL...
- Enter:
https://github.com/Cysharp/ZLogger.git?path=src/ZLogger.Unity/Assets/ZLogger.Unity
- Open Window > Package Manager
- Click + > Add package from git URL...
https://github.com/xpTURN/XLogger.git?path=src/XLogger/Assets/XLogger
- In Edit → XLogger → Player Settings, apply the desired define symbol(s).
- Apply 'ENABLE_XLOGGER' Define Symbol
Enables allXLog*methods. Without this symbol, XLog calls are removed at compile time. - Apply 'ENABLE_XLOGGER_RELEASE' Define Symbol
Use when you wantXLogReleaseoutput in release builds. Without this symbol, those calls are removed at compile time.
- Apply 'ENABLE_XLOGGER' Define Symbol
The following extension methods are available on ILogger:
| Method | Log level | Conditional compile |
|---|---|---|
XLog |
Specified log level | ENABLE_XLOGGER |
XLogTrace |
Trace | ENABLE_XLOGGER |
XLogDebug |
Debug | ENABLE_XLOGGER |
XLogInformation |
Information | ENABLE_XLOGGER |
XLogWarning |
Warning | ENABLE_XLOGGER |
XLogError |
Error | ENABLE_XLOGGER |
XLogCritical |
Critical | ENABLE_XLOGGER |
XLogRelease |
Specified log level | ENABLE_XLOGGER_RELEASE |
- You can use interpolated strings as-is; like ZLogger, structured logging and caller info (method name, file path, line number) are included.
⚠️ Note: Conditional compilation does not apply when using Log* or ZLog* instead of the XLog* methods.
using Microsoft.Extensions.Logging;
using ILogger = Microsoft.Extensions.Logging.ILogger;
using ZLogger;
using ZLogger.Unity;
using UnityEngine;
public class SimpleLogger : MonoBehaviour
{
ILogger logger;
int frame = 0;
int count = 0;
long value = 1000;
string info = "MyGame";
void Awake()
{
// LoggerFactory setup (same as ZLogger)
var loggerFactory = LoggerFactory.Create(logging =>
{
logging.SetMinimumLevel(LogLevel.Trace);
logging.AddZLoggerUnityDebug();
});
logger = loggerFactory.CreateLogger("MyCategory");
}
void Update()
{
++frame;
++count;
// If ENABLE_XLOGGER is not defined, the following calls are not included in the build output
logger.XLogInformation($"Start! Frame: {frame}");
logger.XLogDebug($"Value: {value}");
logger.XLogWarning($"Something: {(name, count)}"); // named
// Output only when ENABLE_XLOGGER_RELEASE is defined
logger.XLogRelease(LogLevel.Information, $"Release-only message: {info}");
}
}- ENABLE_XLOGGER
Enables all
XLog*calls (except XLogRelease). If removed, those calls are eliminated at compile time with no runtime cost. - ENABLE_XLOGGER_RELEASE
Enables only
XLogRelease. Use when you want to disable debug XLog and keep only the messages needed in release.
You can add or remove symbols per platform under Edit → XLogger → Player Settings.
- Both debug and release log code are present in the build.
- Only release log code remains.
See LICENSE.

