From c997b6c1a2982721fe1683d0ec2407cfbf40f17a Mon Sep 17 00:00:00 2001 From: EonaCat Date: Fri, 17 May 2024 07:35:09 +0200 Subject: [PATCH] Added null check to exception message formatting --- EonaCat.Logger/EonaCat.Logger.csproj | 4 ++-- EonaCat.Logger/Extensions/ExceptionExtensions.cs | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/EonaCat.Logger/EonaCat.Logger.csproj b/EonaCat.Logger/EonaCat.Logger.csproj index 748eee2..727b90c 100644 --- a/EonaCat.Logger/EonaCat.Logger.csproj +++ b/EonaCat.Logger/EonaCat.Logger.csproj @@ -3,7 +3,7 @@ .netstandard2.1; net6.0; net7.0; net8.0; net4.8; icon.ico latest - 1.2.8 + 1.2.9 EonaCat (Jeroen Saey) true EonaCat (Jeroen Saey) @@ -24,7 +24,7 @@ - 1.2.8+{chash:10}.{c:ymd} + 1.2.9+{chash:10}.{c:ymd} true true v[0-9]* diff --git a/EonaCat.Logger/Extensions/ExceptionExtensions.cs b/EonaCat.Logger/Extensions/ExceptionExtensions.cs index 7fedc30..8f4090e 100644 --- a/EonaCat.Logger/Extensions/ExceptionExtensions.cs +++ b/EonaCat.Logger/Extensions/ExceptionExtensions.cs @@ -14,8 +14,14 @@ public static class ExceptionExtensions var st = new StackTrace(exception, true); var frame = st.GetFrame(0); - var fileLine = frame.GetFileLineNumber(); - var filename = frame.GetFileName(); + int fileLine = -1; + string filename = "Unknown"; + + if (frame != null) + { + fileLine = frame.GetFileLineNumber(); + filename = frame.GetFileName(); + } var sb = new StringBuilder();