Skip to content

Commit e1ec4a7

Browse files
Deep Logging to help extend Bitmap tools and help in testing and debugging
1 parent 900d966 commit e1ec4a7

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

src/Inventory.App/Common/VirtualCollection/VirtualCollection.cs

+11-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ abstract public partial class VirtualCollection<T> : IItemsRangeInfo, INotifyCol
3232
public readonly int RangeSize;
3333

3434
private DispatcherTimer _timer = null;
35-
36-
public VirtualCollection(ILogService logService, int rangeSize = 16)
35+
bool MustExploreDeepExceptions { get; set; }
36+
public VirtualCollection(ILogService logService, int rangeSize = 16, bool mustExploreDeepExceptions=false)
3737
{
38+
MustExploreDeepExceptions = mustExploreDeepExceptions;
3839
LogService = logService;
3940

4041
RangeSize = rangeSize;
@@ -146,7 +147,14 @@ private async Task FetchRange(ItemIndexRange trackedRange)
146147

147148
protected async void LogException(string source, string action, Exception exception)
148149
{
149-
await LogService.WriteAsync(LogType.Error, source, action, exception.Message, exception.ToString());
150+
if (MustExploreDeepExceptions == false)
151+
{
152+
await LogService.WriteAsync(LogType.Error, source, action, exception.Message, exception.ToString());
153+
}
154+
else
155+
{
156+
await LogService.WriteAsync(LogType.Error, source, action, exception);
157+
}
150158
}
151159

152160
virtual public void Dispose() { }

src/Inventory.App/Services/Infrastructure/LogService/LogService.cs

+12-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,16 @@ public LogService(IMessageService messageService)
3030
}
3131

3232
public IMessageService MessageService { get; }
33-
33+
public async Task WriteAsync(LogType type, string source, string action, Exception ex)
34+
{
35+
await WriteAsync(LogType.Error, source, action, ex.Message, ex.ToString());
36+
Exception deepException = ex.InnerException;
37+
while(deepException!=null)
38+
{
39+
await WriteAsync(LogType.Error, source, action, deepException.Message, deepException.ToString());
40+
deepException = deepException.InnerException;
41+
}
42+
}
3443
public async Task WriteAsync(LogType type, string source, string action, string message, string description)
3544
{
3645
var appLog = new AppLog()
@@ -145,5 +154,7 @@ private AppLogModel CreateAppLogModel(AppLog source)
145154
Description = source.Description,
146155
};
147156
}
157+
158+
148159
}
149160
}

src/Inventory.ViewModels/Infrastructure/Services/ILogService.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace Inventory.Services
2424
public interface ILogService
2525
{
2626
Task WriteAsync(LogType type, string source, string action, string message, string description);
27-
27+
Task WriteAsync(LogType type, string source, string action, Exception ex);
2828
Task<AppLogModel> GetLogAsync(long id);
2929
Task<IList<AppLogModel>> GetLogsAsync(DataRequest<AppLog> request);
3030
Task<IList<AppLogModel>> GetLogsAsync(int skip, int take, DataRequest<AppLog> request);

0 commit comments

Comments
 (0)