diff --git a/StableDiffusion.NET/EventArgs/StableDiffusionLogEventArgs.cs b/StableDiffusion.NET/EventArgs/StableDiffusionLogEventArgs.cs
new file mode 100644
index 0000000..e8339fb
--- /dev/null
+++ b/StableDiffusion.NET/EventArgs/StableDiffusionLogEventArgs.cs
@@ -0,0 +1,11 @@
+namespace StableDiffusion.NET;
+
+public class StableDiffusionLogEventArgs(LogLevel level, string text)
+{
+ #region Properties & Fields
+
+ public LogLevel Level { get; } = level;
+ public string Text { get; } = text;
+
+ #endregion
+}
\ No newline at end of file
diff --git a/StableDiffusion.NET/Native.cs b/StableDiffusion.NET/Native.cs
index caac38f..b6b1757 100644
--- a/StableDiffusion.NET/Native.cs
+++ b/StableDiffusion.NET/Native.cs
@@ -21,6 +21,12 @@ internal unsafe partial class Native
#endregion
+ #region Delegates
+
+ internal delegate void sd_log_cb_t(sd_log_level_t level, [MarshalAs(UnmanagedType.LPStr)] string text, void* data);
+
+ #endregion
+
#region DLL-Import
internal struct sd_ctx_t;
@@ -98,5 +104,8 @@ internal unsafe partial class Native
sd_image_t input_image,
int upscale_factor);
+ [LibraryImport(LIB_NAME, EntryPoint = "sd_set_log_callback")]
+ internal static partial void sd_set_log_callback(sd_log_cb_t sd_log_cb, void* data);
+
#endregion
}
\ No newline at end of file
diff --git a/StableDiffusion.NET/StableDiffusion.NET.csproj.DotSettings b/StableDiffusion.NET/StableDiffusion.NET.csproj.DotSettings
index ba0522c..eac4bf8 100644
--- a/StableDiffusion.NET/StableDiffusion.NET.csproj.DotSettings
+++ b/StableDiffusion.NET/StableDiffusion.NET.csproj.DotSettings
@@ -1,4 +1,5 @@
True
True
+ True
True
\ No newline at end of file
diff --git a/StableDiffusion.NET/StableDiffusionModel.cs b/StableDiffusion.NET/StableDiffusionModel.cs
index bd77a0f..cb95919 100644
--- a/StableDiffusion.NET/StableDiffusionModel.cs
+++ b/StableDiffusion.NET/StableDiffusionModel.cs
@@ -18,8 +18,19 @@ public sealed unsafe class StableDiffusionModel : IDisposable
#endregion
+ #region Events
+
+ public static event EventHandler? Log;
+
+ #endregion
+
#region Constructors
+ static StableDiffusionModel()
+ {
+ Native.sd_set_log_callback(OnNativeLog, null);
+ }
+
public StableDiffusionModel(string modelPath, ModelParameter parameter, UpscalerModelParameter? upscalerParameter = null)
{
this._modelPath = modelPath;
@@ -177,5 +188,14 @@ public sealed unsafe class StableDiffusionModel : IDisposable
public static int GetNumPhysicalCores() => Native.get_num_physical_cores();
+ private static void OnNativeLog(LogLevel level, string text, void* data)
+ {
+ try
+ {
+ Log?.Invoke(null, new StableDiffusionLogEventArgs(level, text));
+ }
+ catch { /**/ }
+ }
+
#endregion
}
diff --git a/build.bat b/build.bat
index 212ceb5..d075235 100644
--- a/build.bat
+++ b/build.bat
@@ -4,7 +4,7 @@ if not exist stable-diffusion.cpp (
cd stable-diffusion.cpp
git fetch
-git checkout 2c5f3fc53a040a0f97ff8f359e8f8d1385bfd154
+git checkout 7cb41b190fb9b4703f1737171cefd0abec861154
git submodule init
git submodule update