Update ChatGptService.cs

This commit is contained in:
Madpeter 2024-10-01 11:05:43 +01:00
parent 39efdbdba2
commit d5c59e2d31

View file

@ -18,6 +18,8 @@ using OpenAI.ObjectModels;
using OpenAI.ObjectModels.ResponseModels;
using System.Threading.Tasks;
using OpenAI.Interfaces;
using System.Diagnostics;
using Swan;
namespace SecondBotEvents.Services
{
@ -412,7 +414,14 @@ namespace SecondBotEvents.Services
catch (Exception ex)
{
// Handle other potential errors
Console.WriteLine("An error occurred: " + ex.Message);
// Get stack trace for the exception with source file information
var st = new StackTrace(ex, true);
// Get the top stack frame
var frame = st.GetFrame(0);
// Get the line number from the stack frame
var line = frame.GetFileLineNumber();
LogFormater.Warn("An error occurred: " + ex.Message + " on line "+ line.ToString());
LogFormater.Debug(ex.ToJson());
}
}