refine error and warn logging

This commit is contained in:
Jicheng Lu 2025-05-02 11:31:28 -05:00
parent a26f918161
commit d703477b4b
35 changed files with 63 additions and 81 deletions

View file

@ -53,7 +53,7 @@ public partial class ConversationService
#if DEBUG
Console.WriteLine($"\r\n{error}\r\n");
#else
_logger.LogError($"{error}");
_logger.LogError(ex, $"{error}");
#endif
}
}

View file

@ -66,7 +66,7 @@ public partial class FileInstructService
}
catch (Exception ex)
{
_logger.LogError($"Error when analyzing pdf in file service: {ex.Message}\r\n{ex.InnerException}");
_logger.LogError(ex, $"Error when analyzing pdf in file service.");
return content;
}
finally
@ -113,7 +113,7 @@ public partial class FileInstructService
}
catch (Exception ex)
{
_logger.LogWarning($"Error when saving pdf file: {ex.Message}\r\n{ex.InnerException}");
_logger.LogWarning(ex, $"Error when saving pdf file.");
continue;
}
}
@ -141,7 +141,7 @@ public partial class FileInstructService
}
catch (Exception ex)
{
_logger.LogWarning($"Error when converting pdf file to images ({file}): {ex.Message}\r\n{ex.InnerException}");
_logger.LogWarning(ex, $"Error when converting pdf file to images ({file}).");
continue;
}
}

View file

@ -108,7 +108,7 @@ public partial class FileInstructService
}
catch (Exception ex)
{
_logger.LogWarning($"Error when selecting files. {ex.Message}\r\n{ex.InnerException}");
_logger.LogWarning(ex, $"Error when selecting files.");
return new List<MessageFileModel>();
}
}

View file

@ -24,7 +24,7 @@ public partial class LocalFileStorageService
}
catch (Exception ex)
{
_logger.LogWarning($"Error when saving speech file. {fileName} ({conversationId})\r\n{ex.Message}\r\n{ex.InnerException}");
_logger.LogWarning(ex, $"Error when saving speech file. {fileName} (conv id: {conversationId})");
return false;
}
}

View file

@ -153,7 +153,7 @@ public partial class LocalFileStorageService
}
catch (Exception ex)
{
_logger.LogWarning($"Error when saving message file {file.FileName}: {ex.Message}\r\n{ex.InnerException}");
_logger.LogWarning(ex, $"Error when saving message file {file.FileName} (conv id: {conversationId}).");
continue;
}
}
@ -333,7 +333,7 @@ public partial class LocalFileStorageService
}
catch (Exception ex)
{
_logger.LogWarning($"Error when getting message file screenshots {file} (messageId: {messageId}), Error: {ex.Message}\r\n{ex.InnerException}");
_logger.LogWarning(ex, $"Error when getting message file screenshots {file} (messageId: {messageId})");
return files;
}
}

View file

@ -31,9 +31,8 @@ public partial class LocalFileStorageService
}
catch (Exception ex)
{
_logger.LogWarning($"Error when saving knowledge file " +
$"(Vector store provider: {vectorStoreProvider}, Collection: {collectionName}, File name: {fileName})." +
$"\r\n{ex.Message}\r\n{ex.InnerException}");
_logger.LogWarning(ex, $"Error when saving knowledge file " +
$"(Vector store provider: {vectorStoreProvider}, Collection: {collectionName}, File name: {fileName}).");
return false;
}
}

View file

@ -40,7 +40,7 @@ public partial class LocalFileStorageService
}
catch (Exception ex)
{
_logger.LogWarning($"Error when saving user avatar: {ex.Message}\r\n{ex.InnerException}");
_logger.LogWarning(ex, $"Error when saving user avatar (user id: {_user.Id})");
return false;
}
}

View file

@ -84,7 +84,7 @@ public class ExecuteTemplateFn : IFunctionCallback
catch (Exception ex)
{
var error = $"Error when getting agent {agent.Name} instruction response.";
_logger.LogWarning($"{error} {ex.Message}\r\n{ex.InnerException}");
_logger.LogWarning(ex, $"{error} (template name: {templateName})");
return error;
}

View file

@ -45,7 +45,7 @@ public partial class InstructService
}
catch (Exception ex)
{
_logger.LogWarning($"Error when getting ai response, {ex.Message}\r\n{ex.InnerException}");
_logger.LogWarning(ex, $"Error when getting ai response");
}
return result;

View file

@ -26,7 +26,7 @@ public partial class FileRepository
}
catch (Exception ex)
{
_logger.LogError($"Error when saving crontab item: {ex.Message}\r\n{ex.InnerException}");
_logger.LogError(ex, $"Error when saving crontab item (agent id: {cron.AgentId}, conv id: {cron.ConversationId}).");
return false;
}
}
@ -57,7 +57,7 @@ public partial class FileRepository
}
catch (Exception ex)
{
_logger.LogError($"Error when deleting crontab item (${conversationId}): {ex.Message}\r\n{ex.InnerException}");
_logger.LogError(ex, $"Error when deleting crontab item (conv id: {conversationId}).");
return false;
}
}

View file

@ -89,7 +89,7 @@ public class BotSharpStatsService : IBotSharpStatsService
}
catch (Exception ex)
{
_logger.LogError($"Error when updating global stats {input.Metric}-{input.Dimension}-{input.DimRefVal}. {ex.Message}\r\n{ex.InnerException}");
_logger.LogError(ex, $"Error when updating global stats {input.Metric}-{input.Dimension}-{input.DimRefVal}.");
return false;
}
}

View file

@ -94,7 +94,7 @@ public class NativeWhisperProvider : IAudioTranscription
catch (Exception ex)
{
var error = "Failed to load whisper model";
_logger.LogWarning($"${error}: {ex.Message}\r\n{ex.InnerException}");
_logger.LogWarning(ex, $"{error}");
throw new Exception($"{error}: {ex.Message}");
}
}

View file

@ -195,8 +195,7 @@ public class ChatHubConversationHook : ConversationHookBase
}
catch (Exception ex)
{
_logger.LogWarning($"Failed to init client conversation in {nameof(ChatHubConversationHook)} (conversation id: {conversationId})" +
$"\r\n{ex.Message}\r\n{ex.InnerException}");
_logger.LogWarning(ex, $"Failed to init client conversation in {nameof(ChatHubConversationHook)} (conversation id: {conversationId})");
}
}
@ -215,8 +214,7 @@ public class ChatHubConversationHook : ConversationHookBase
}
catch (Exception ex)
{
_logger.LogWarning($"Failed to receive assistant message in {nameof(ChatHubConversationHook)} (conversation id: {conversationId})" +
$"\r\n{ex.Message}\r\n{ex.InnerException}");
_logger.LogWarning(ex, $"Failed to receive assistant message in {nameof(ChatHubConversationHook)} (conversation id: {conversationId})");
}
}
@ -235,8 +233,7 @@ public class ChatHubConversationHook : ConversationHookBase
}
catch (Exception ex)
{
_logger.LogWarning($"Failed to receive assistant message in {nameof(ChatHubConversationHook)} (conversation id: {conversationId})" +
$"\r\n{ex.Message}\r\n{ex.InnerException}");
_logger.LogWarning(ex, $"Failed to receive assistant message in {nameof(ChatHubConversationHook)} (conversation id: {conversationId})");
}
}
@ -256,8 +253,7 @@ public class ChatHubConversationHook : ConversationHookBase
}
catch (Exception ex)
{
_logger.LogWarning($"Failed to generate sender action in {nameof(ChatHubConversationHook)} (conversation id: {conversationId})" +
$"\r\n{ex.Message}\r\n{ex.InnerException}");
_logger.LogWarning(ex, $"Failed to generate sender action in {nameof(ChatHubConversationHook)} (conversation id: {conversationId})");
}
}
@ -276,8 +272,7 @@ public class ChatHubConversationHook : ConversationHookBase
}
catch (Exception ex)
{
_logger.LogWarning($"Failed to delete message in {nameof(ChatHubConversationHook)} (conversation id: {conversationId})" +
$"\r\n{ex.Message}\r\n{ex.InnerException}");
_logger.LogWarning(ex, $"Failed to delete message in {nameof(ChatHubConversationHook)} (conversation id: {conversationId})");
}
}
@ -296,8 +291,7 @@ public class ChatHubConversationHook : ConversationHookBase
}
catch (Exception ex)
{
_logger.LogWarning($"Failed to generate notification in {nameof(ChatHubConversationHook)} (conversation id: {conversationId})" +
$"\r\n{ex.Message}\r\n{ex.InnerException}");
_logger.LogWarning(ex, $"Failed to generate notification in {nameof(ChatHubConversationHook)} (conversation id: {conversationId})");
}
}
#endregion

View file

@ -484,8 +484,7 @@ public class StreamingLogHook : ConversationHookBase, IContentGeneratingHook, IR
}
catch (Exception ex)
{
_logger.LogWarning($"Failed to send content log in {nameof(StreamingLogHook)} (conversation id: {conversationId})." +
$"\r\n{ex.Message}\r\n{ex.InnerException}");
_logger.LogWarning(ex, $"Failed to send content log in {nameof(StreamingLogHook)} (conversation id: {conversationId}).");
}
}
@ -504,8 +503,7 @@ public class StreamingLogHook : ConversationHookBase, IContentGeneratingHook, IR
}
catch (Exception ex)
{
_logger.LogWarning($"Failed to send state log in {nameof(StreamingLogHook)} (conversation id: {conversationId})." +
$"\r\n{ex.Message}\r\n{ex.InnerException}");
_logger.LogWarning(ex, $"Failed to send state log in {nameof(StreamingLogHook)} (conversation id: {conversationId}).");
}
}
@ -524,8 +522,7 @@ public class StreamingLogHook : ConversationHookBase, IContentGeneratingHook, IR
}
catch (Exception ex)
{
_logger.LogWarning($"Failed to send agent queue log in {nameof(StreamingLogHook)} (conversation id: {conversationId})." +
$"\r\n{ex.Message}\r\n{ex.InnerException}");
_logger.LogWarning(ex, $"Failed to send agent queue log in {nameof(StreamingLogHook)} (conversation id: {conversationId}).");
}
}
@ -544,8 +541,7 @@ public class StreamingLogHook : ConversationHookBase, IContentGeneratingHook, IR
}
catch (Exception ex)
{
_logger.LogWarning($"Failed to send state change in {nameof(StreamingLogHook)} (conversation id: {conversationId})." +
$"\r\n{ex.Message}\r\n{ex.InnerException}");
_logger.LogWarning(ex, $"Failed to send state change in {nameof(StreamingLogHook)} (conversation id: {conversationId}).");
}
}

View file

@ -103,8 +103,7 @@ public class WelcomeHook : ConversationHookBase
}
catch (Exception ex)
{
_logger.LogWarning($"Failed to send event in {nameof(WelcomeHook)} (conversation id: {conversationId})." +
$"\r\n{ex.Message}\r\n{ex.InnerException}");
_logger.LogWarning(ex, $"Failed to send event in {nameof(WelcomeHook)} (conversation id: {conversationId}).");
}
}
}

View file

@ -64,8 +64,7 @@ public class SignalRHub : Hub
}
catch (Exception ex)
{
_logger.LogWarning($"Failed to add chat group in {nameof(SignalRHub)} (conversation id: {conversationId})." +
$"\r\n{ex.Message}\r\n{ex.InnerException}");
_logger.LogWarning(ex, $"Failed to add chat group in {nameof(SignalRHub)} (conversation id: {conversationId}).");
}
}
}

View file

@ -64,7 +64,7 @@ public class HandleEmailSenderFn : IFunctionCallback
catch (Exception ex)
{
var msg = $"Failed to send the email. {ex.Message}";
_logger.LogError($"{msg}\n(Error: {ex.Message}\r\n{ex.InnerException})");
_logger.LogError(ex, $"{msg}");
message.Content = msg;
return false;
}

View file

@ -90,7 +90,7 @@ public class EditImageFn : IFunctionCallback
catch (Exception ex)
{
var error = $"Error when getting image edit response. {ex.Message}";
_logger.LogWarning($"{error}\r\n{ex.InnerException}");
_logger.LogWarning(ex, $"{error}");
return error;
}
}

View file

@ -68,7 +68,7 @@ public class GenerateImageFn : IFunctionCallback
catch (Exception ex)
{
var error = $"Error when generating image.";
_logger.LogWarning($"{error} {ex.Message}\r\n{ex.InnerException}");
_logger.LogWarning(ex, $"{error}");
return error;
}
}

View file

@ -108,7 +108,7 @@ public class ReadImageFn : IFunctionCallback
catch (Exception ex)
{
var error = $"Error when analyzing images.";
_logger.LogWarning($"{error} {ex.Message}\r\n{ex.InnerException}");
_logger.LogWarning(ex, $"{error}");
return error;
}
}

View file

@ -86,7 +86,7 @@ public class ReadPdfFn : IFunctionCallback
catch (Exception ex)
{
var error = $"Error when analyzing pdf file(s).";
_logger.LogWarning($"{error} {ex.Message}\r\n{ex.InnerException}");
_logger.LogWarning(ex, $"{error}");
return error;
}
}

View file

@ -81,7 +81,7 @@ public class GraphDb : IGraphDb
}
catch (Exception ex)
{
_logger.LogError($"Error when fetching Lessen GLM response (Endpoint: {url}). {ex.Message}\r\n{ex.InnerException}");
_logger.LogError(ex, $"Error when fetching Lessen GLM response (Endpoint: {url}).");
return result;
}
}

View file

@ -45,7 +45,7 @@ public class HandleHttpRequestFn : IFunctionCallback
catch (Exception ex)
{
var msg = $"Fail when sending http request. Url: {url}, method: {method}, content: {content}";
_logger.LogError($"{msg}\n(Error: {ex.Message}\r\n{ex.InnerException})");
_logger.LogError(ex, $"{msg}");
message.Content = msg;
return false;
}

View file

@ -98,7 +98,7 @@ public partial class KnowledgeService
}
catch (Exception ex)
{
_logger.LogError($"Error when processing knowledge file ({file.FileName}). {ex.Message}\r\n{ex.InnerException}");
_logger.LogError(ex, $"Error when processing knowledge file ({file.FileName}).");
failedFiles.Add(file.FileName);
continue;
}
@ -170,9 +170,7 @@ public partial class KnowledgeService
}
catch (Exception ex)
{
_logger.LogWarning($"Error when importing doc content to knowledgebase ({collectionName}-{fileName})" +
$"\r\n{ex.Message}" +
$"\r\n{ex.InnerException}");
_logger.LogWarning(ex, $"Error when importing doc content to knowledgebase ({collectionName}-{fileName})");
return false;
}
}
@ -214,9 +212,8 @@ public partial class KnowledgeService
}
catch (Exception ex)
{
_logger.LogWarning($"Error when deleting knowledge document " +
$"(Collection: {collectionName}, File id: {fileId})" +
$"\r\n{ex.Message}\r\n{ex.InnerException}");
_logger.LogWarning(ex, $"Error when deleting knowledge document " +
$"(Collection: {collectionName}, File id: {fileId})");
return false;
}
}

View file

@ -15,7 +15,7 @@ public partial class KnowledgeService
}
catch (Exception ex)
{
_logger.LogWarning($"Error when searching graph knowledge (Query: {query}). {ex.Message}\r\n{ex.InnerException}");
_logger.LogWarning(ex, $"Error when searching graph knowledge (Query: {query}).");
return new GraphSearchResult();
}
}

View file

@ -26,7 +26,7 @@ public partial class MongoRepository
}
catch (Exception ex)
{
_logger.LogError($"Error when saving crontab item: {ex.Message}\r\n{ex.InnerException}");
_logger.LogError(ex, $"Error when saving crontab item (agent id: {item.AgentId}, conv id: {item.ConversationId}).");
return false;
}
}

View file

@ -456,7 +456,7 @@ public class QdrantDb : IVectorDb
}
catch (Exception ex)
{
_logger.LogError($"Error when downloading Qdrant snapshot (Endpoint: {url}, Snapshot: {snapshotFileName}). {ex.Message}\r\n{ex.InnerException}");
_logger.LogError(ex, $"Error when downloading Qdrant snapshot (Endpoint: {url}, Snapshot: {snapshotFileName}).");
return BinaryData.Empty;
}
}
@ -497,7 +497,7 @@ public class QdrantDb : IVectorDb
}
catch (Exception ex)
{
_logger.LogError($"Error when uploading Qdrant snapshot (Endpoint: {url}, Snapshot: {snapshotFileName}). {ex.Message}\r\n{ex.InnerException}");
_logger.LogError(ex, $"Error when uploading Qdrant snapshot (Endpoint: {url}, Snapshot: {snapshotFileName}).");
return false;
}
}

View file

@ -73,7 +73,7 @@ public class GetTableDefinitionFn : IFunctionCallback
}
catch (Exception ex)
{
_logger.LogWarning($"Error when getting ddl statement of table {table}. {ex.Message}\r\n{ex.InnerException}");
_logger.LogWarning(ex, $"Error when getting ddl statement of table {table}.");
}
}
@ -125,7 +125,7 @@ public class GetTableDefinitionFn : IFunctionCallback
}
catch (Exception ex)
{
_logger.LogWarning($"Error when getting ddl statement of table {table}. {ex.Message}\r\n{ex.InnerException}");
_logger.LogWarning(ex, $"Error when getting ddl statement of table {table}.");
}
}
@ -165,7 +165,7 @@ public class GetTableDefinitionFn : IFunctionCallback
}
catch (Exception ex)
{
_logger.LogWarning($"Error when getting ddl statement of table {table}. {ex.Message}\r\n{ex.InnerException}");
_logger.LogWarning(ex, $"Error when getting ddl statement of table {table}.");
}
}
connection.Close();

View file

@ -82,8 +82,8 @@ public class DbKnowledgeService
}
catch (Exception ex)
{
var note = $"Error processing table {table}: {ex.Message}\r\n{ex.InnerException}";
_logger.LogWarning(note);
var note = $"Error processing table {table}.";
_logger.LogWarning(ex, note);
}
}

View file

@ -67,7 +67,7 @@ public class GetTableDefinitionFn : IFunctionCallback
}
catch (Exception ex)
{
_logger.LogWarning($"Error when getting ddl statement of table {table}. {ex.Message}\r\n{ex.InnerException}");
_logger.LogWarning(ex, $"Error when getting ddl statement of table {table}.");
}
}
@ -119,7 +119,7 @@ public class GetTableDefinitionFn : IFunctionCallback
}
catch (Exception ex)
{
_logger.LogWarning($"Error when getting ddl statement of table {table}. {ex.Message}\r\n{ex.InnerException}");
_logger.LogWarning(ex, $"Error when getting ddl statement of table {table}.");
}
}
@ -159,7 +159,7 @@ public class GetTableDefinitionFn : IFunctionCallback
}
catch (Exception ex)
{
_logger.LogWarning($"Error when getting ddl statement of table {table}. {ex.Message}\r\n{ex.InnerException}");
_logger.LogWarning(ex, $"Error when getting ddl statement of table {table}.");
}
}
connection.Close();

View file

@ -17,7 +17,7 @@ public partial class TencentCosService
}
catch (Exception ex)
{
_logger.LogWarning($"Error when saving speech file. {fileName} ({conversationId})\r\n{ex.Message}\r\n{ex.InnerException}");
_logger.LogWarning(ex, $"Error when saving speech file. {fileName} (conv id: {conversationId})");
return false;
}
}

View file

@ -20,7 +20,7 @@ public partial class TencentCosService
}
catch (Exception ex)
{
_logger.LogWarning($"Error when getting files: {ex.Message}\r\n{ex.InnerException}");
_logger.LogWarning(ex, $"Error when getting files (path: {relativePath}).");
return Enumerable.Empty<string>();
}
}
@ -33,7 +33,7 @@ public partial class TencentCosService
}
catch (Exception ex)
{
_logger.LogWarning($"Error when getting file bytes: {ex.Message}\r\n{ex.InnerException}");
_logger.LogWarning(ex, $"Error when getting file bytes (url: {fileStorageUrl}).");
return Array.Empty<byte>();
}
}
@ -48,7 +48,7 @@ public partial class TencentCosService
}
catch (Exception ex)
{
_logger.LogWarning($"Error when saving file stream to path: {ex.Message}\r\n{ex.InnerException}");
_logger.LogWarning(ex, $"Error when saving file stream to path ({filePath}).");
return false;
}
}
@ -63,7 +63,7 @@ public partial class TencentCosService
}
catch (Exception ex)
{
_logger.LogWarning($"Error when saving file bytes to path: {ex.Message}\r\n{ex.InnerException}");
_logger.LogWarning(ex, $"Error when saving file bytes to path ({filePath}).");
return false;
}
}

View file

@ -138,7 +138,7 @@ public partial class TencentCosService
}
catch (Exception ex)
{
_logger.LogWarning($"Error when saving message file {file.FileName}: {ex.Message}\r\n{ex.InnerException}");
_logger.LogWarning(ex,$"Error when saving message file {file.FileName} (conv id: {conversationId}).");
continue;
}
}
@ -318,7 +318,7 @@ public partial class TencentCosService
}
catch (Exception ex)
{
_logger.LogWarning($"Error when getting message file screenshots {file} (messageId: {messageId}), Error: {ex.Message}\r\n{ex.InnerException}");
_logger.LogWarning(ex, $"Error when getting message file screenshots {file} (messageId: {messageId}).");
return files;
}
}

View file

@ -25,9 +25,8 @@ public partial class TencentCosService
}
catch (Exception ex)
{
_logger.LogWarning($"Error when saving knowledge file " +
$"(Vector store provider: {vectorStoreProvider}, Collection: {collectionName}, File name: {fileName})." +
$"\r\n{ex.Message}\r\n{ex.InnerException}");
_logger.LogWarning(ex, $"Error when saving knowledge file " +
$"(Vector store provider: {vectorStoreProvider}, Collection: {collectionName}, File name: {fileName}).");
return false;
}
}
@ -107,8 +106,7 @@ public partial class TencentCosService
}
catch (Exception ex)
{
_logger.LogWarning($"Error when downloading collection file ({collectionName}-{vectorStoreProvider}-{fileId}-{fileName})" +
$"\r\n{ex.Message}\r\n{ex.InnerException}");
_logger.LogWarning(ex, $"Error when downloading collection file ({collectionName}-{vectorStoreProvider}-{fileId}-{fileName})");
return BinaryData.Empty;
}
}

View file

@ -36,7 +36,7 @@ public partial class TencentCosService
}
catch (Exception ex)
{
_logger.LogWarning($"Error when saving user avatar: {ex.Message}\r\n{ex.InnerException}");
_logger.LogWarning(ex, $"Error when saving user avatar (user id: {_user.Id}).");
return false;
}
}