UnrealSharp
  • Home
  • FAQ
  • Getting Started
    • Setup
    • Your First Script
    • Debugging
    • Packaging
  • Documentation
    • Classes
      • Properties
        • C++ Functions As C# Properties
        • C++ Properties with Getters/Setters
      • Functions
        • Flags
        • MetaData
      • Default Actor Components
      • Helper Methods
    • Structs
    • Enums
    • Interfaces
    • Delegates
    • Collections
      • TArray
      • TNativeArray
      • TSet
      • TMap
    • Multiplayer
      • Replicated Properties
      • RPCs (Remote Procedure Calls)
      • Replicated UObjects
    • Primary Data Assets
      • Loading Primary Data Assets
    • Loading Soft References
    • Trace Channels
    • Static Variables
      • FWorldStaticVar<T>
      • FGameStaticVar<T>
    • Logging
    • Async
    • Gameplay Tags
      • Gameplay Tag Container
    • Extension / Mixin Methods
    • Subsystems
    • Module Lifecycle
  • Links
    • Github Repository
    • Roadmap
    • Discord
Powered by GitBook
On this page
  1. Documentation

Logging

Enable Custom Logs

Need to include this assembly in your csproj:

<Reference Include="UnrealSharp.Log">
  <HintPath>..\..\Plugins\UnrealSharp\Binaries\Managed\net9.0\UnrealSharp.Log.dll</HintPath>
</Reference>

Define Custom Log Categories

The [CustomLog] attribute is used on a partial (and preferably static) class to define a custom log category, for the Unreal Engine output log.

The category's API will then generate automatically with methods such as Log / LogWarning / LogError / LogFatal.

[CustomLog]
public static partial class LogMyFirstLog;

[CustomLog(ELogVerbosity.Verbose)]
public static partial class LogMySecondLog;
  • LogMyFirstLog: Defaults to ELogVerbosity.Display when no verbosity is specified.

  • LogMySecondLog: Explicitly uses ELogVerbosity.Verbose.


Use the Log Categories

Here’s an example of how to log with your custom categories:

[UClass]
public class ALogShowcase : AActor
{
    public ALogShowcase()
    {
        LogMyFirstLog.Log("ALogShowcase constructor executed");
    }

    protected override void BeginPlay()
    {
        LogMyFirstLog.Log("BeginPlay executed");
        base.BeginPlay();
    }
}

And they will show up like this in the output log in the engine:

LogMyFirstLog: Display: ALogShowcase constructor executed
LogMyFirstLog: Display: BeginPlay executed
PreviousFGameStaticVar<T>NextAsync

Last updated 3 months ago