GlobalShared.CommonUtils.Library
Common Utilities Used For Project.
1.The Utils class offers helper functions for string manipulation, data conversion, configuration retrieval (Appsettings and Web.Config), encryption (SHA-256) and MD5, formatting (currency, date), and standardized response handling and also handleException using log4Net.
2.The RestExtension class extends HttpClient, providing async methods for GET, POST, and PATCH requests. It handles headers, request creation, response deserialization, and error handling via ApiResponse. It supports JSON, lists, and binary data (PDFs) with cancellation tokens to prevent long-running requests. Potential improvements include strongly typed models, better logging, and optimized header management.
3.The Logs class manages structured logging for security (SIEMLogs), exceptions, and API requests. It dynamically creates log files, ensures directory existence, sets access permissions, and timestamps entries for monitoring, debugging, and auditing.
4.DataServiceUtils provides async methods for executing SQL queries using SqlConnection. It includes GetScalarAsync for fetching a single value and ExecuteNonQueryAsync for non-query commands, both supporting optional SQL parameters. It ensures resource management and preserves exception stack traces, but CommandTimeout = 0 may cause indefinite waits.
5.MongoDataServiceUtils is a utility class that provides asynchronous CRUD operations for MongoDB. It includes methods for inserting (InsertDocumentAsync), updating (UpdateDocumentAsync), retrieving (GetDocumentsAsync), and deleting (DeleteDocumentAsync) documents based on filter criteria. Additionally, it offers a synchronous method (CountDocuments) to count documents in a collection. This class simplifies MongoDB interactions by providing reusable and efficient database operations.
FileLogger Class :-
The FileLogger class provides a simple method to log informational messages to a specified file path. The static method LogInformation takes a message and a logging path as input.
It first checks whether the directory for the log file exists; if it doesn't, the method creates the directory. Then, it appends the message to the log file,
prefixed with the current timestamp. The method includes basic exception handling to avoid application crashes due to any file I/O errors, although the catch
block is currently empty and does not log or rethrow the exception.
v4.0.16↙ 5.5K