Files
FlaxEngine/Source/Engine/Engine/DebugLogHandler.cs
T
mafiesto4 eebc4951de Merge branch '1.5' into dotnet7
# Conflicts:
#	Source/Platforms/DotNet/NUnit/agents/net40/nunit-agent.exe
#	Source/Platforms/DotNet/NUnit/agents/net40/nunit.engine.api.dll
#	Source/Platforms/DotNet/NUnit/agents/net40/nunit.engine.core.dll
#	Source/Platforms/DotNet/NUnit/agents/net7.0/nunit.agent.addins
#	Source/Platforms/DotNet/NUnit/nunit.engine.api.dll
#	Source/Platforms/DotNet/NUnit/nunit.engine.core.dll
#	Source/Platforms/DotNet/NUnit/nunit.engine.dll
#	Source/Platforms/DotNet/NUnit/nunit3-console.exe
#	Source/Platforms/DotNet/NUnit/nunit3-console.exe.config
#	Source/Platforms/DotNet/NUnit/testcentric.engine.metadata.dll
#	Source/Tools/Flax.Build/Deps/Downloader.cs
#	Source/Tools/Flax.Stats/CodeFrame.cs
#	Source/Tools/Flax.Stats/CodeFrameNode.cs
#	Source/Tools/Flax.Stats/Flax.Stats.Build.cs
#	Source/Tools/Flax.Stats/Languages.cs
#	Source/Tools/Flax.Stats/Program.cs
#	Source/Tools/Flax.Stats/TaskType.cs
#	Source/Tools/Flax.Stats/Tools.cs
#	Source/Tools/FlaxEngine.Tests/TestEditorUtils.cs
2023-01-10 15:49:44 +01:00

86 lines
3.2 KiB
C#

// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Security;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;
namespace FlaxEngine
{
internal partial class DebugLogHandler : ILogHandler
{
/// <summary>
/// Occurs on sending a log message.
/// </summary>
public event LogDelegate SendLog;
/// <summary>
/// Occurs on sending a log message.
/// </summary>
public event LogExceptionDelegate SendExceptionLog;
/// <inheritdoc />
public void LogWrite(LogType logType, string message)
{
Internal_LogWrite(logType, message);
}
/// <inheritdoc />
public void LogException(Exception exception, Object context)
{
Internal_LogException(exception, Object.GetUnmanagedPtr(context));
SendExceptionLog?.Invoke(exception, context);
}
/// <inheritdoc />
public void Log(LogType logType, Object context, string message)
{
if (message == null)
return;
#if BUILD_RELEASE
string stackTrace = null;
#else
string stackTrace = Environment.StackTrace;
#endif
Internal_Log(logType, message, Object.GetUnmanagedPtr(context), stackTrace);
SendLog?.Invoke(logType, message, context, stackTrace);
}
internal static void Internal_SendLog(LogType logType, string message, string stackTrace)
{
if (message == null)
return;
var logger = Debug.Logger;
if (logger.IsLogTypeAllowed(logType))
{
Internal_Log(logType, message, IntPtr.Zero, stackTrace);
((DebugLogHandler)logger.LogHandler).SendLog?.Invoke(logType, message, null, stackTrace);
}
}
internal static void Internal_SendLogException(Exception exception)
{
Debug.Logger.LogException(exception);
}
[LibraryImport("FlaxEngine", EntryPoint = "FlaxEngine.DebugLogHandler::Internal_LogWrite", StringMarshalling = StringMarshalling.Custom, StringMarshallingCustomType = typeof(FlaxEngine.StringMarshaller))]
internal static partial void Internal_LogWrite(LogType level, string msg);
[LibraryImport("FlaxEngine", EntryPoint = "FlaxEngine.DebugLogHandler::Internal_Log", StringMarshalling = StringMarshalling.Custom, StringMarshallingCustomType = typeof(FlaxEngine.StringMarshaller))]
internal static partial void Internal_Log(LogType level, string msg, IntPtr obj, string stackTrace);
[LibraryImport("FlaxEngine", EntryPoint = "FlaxEngine.DebugLogHandler::Internal_LogException", StringMarshalling = StringMarshalling.Custom, StringMarshallingCustomType = typeof(FlaxEngine.StringMarshaller))]
internal static partial void Internal_LogException([MarshalUsing(typeof(FlaxEngine.ExceptionMarshaller))] Exception exception, IntPtr obj);
[SecuritySafeCritical]
public static string Internal_GetStackTrace()
{
var stackTrace = new StackTrace(1, true);
return stackTrace.ToString();
}
}
}