@@ -321,6 +321,8 @@ public async Task<List<BsonFileManagerModel>> ShareFile(string dbName, string bs
321321
322322 public async Task < FileManagerResponse < Syncfusion . Blazor . FileManager . FileManagerDirectoryContent > > itemDeleteAsync ( string dbName , ItemsDeleteEventArgs < Syncfusion . Blazor . FileManager . FileManagerDirectoryContent > args )
323323 {
324+ _logger . LogInformation ( "Deleting items - DbName: {DbName}, Count: {Count}, Path: {Path}" ,
325+ dbName , args . Files . Count ( ) , args . Path ) ;
324326 string [ ] names = args . Files . Select ( x => x . Name ) . ToArray ( ) ;
325327 bool isMyChannel = _ts . isMyChat ( Convert . ToInt64 ( dbName ) ) ;
326328 // args.Response = await FileManagerService.Delete(args.Path, names, args.Files.ToArray());
@@ -634,6 +636,8 @@ public async Task<MemoryStream> getImage(string dbName, string path, string file
634636
635637 public async Task downloadFile ( string dbName , string path , List < string > files , string targetPath , string ? collectionId = null , string ? channelId = null )
636638 {
639+ _logger . LogInformation ( "Starting download - DbName: {DbName}, Path: {Path}, FilesCount: {Count}, TargetPath: {TargetPath}" ,
640+ dbName , path , files . Count , targetPath ) ;
637641 NotificationModel nm = new NotificationModel ( ) ;
638642 try
639643 {
@@ -806,6 +810,8 @@ public static void functionCalll(string dbName, int messageId, string destPath)
806810 }
807811 public virtual async Task downloadFromTelegram ( string dbName , int messageId , string destPath , BsonFileManagerModel file = null , bool shouldWait = false , string path = null )
808812 {
813+ _logger . LogDebug ( "Queueing download from Telegram - DbName: {DbName}, MessageId: {MessageId}, DestPath: {DestPath}" ,
814+ dbName , messageId , destPath ) ;
809815 DownloadModel model = new DownloadModel ( ) ;
810816 model . path = path ?? destPath ;
811817 model . tis = _tis ;
@@ -1130,6 +1136,8 @@ public async Task CreateDatabase(string id)
11301136
11311137 public async Task AddUploadFileFromServer ( string dbName , string currentPath , List < Syncfusion . Blazor . FileManager . FileManagerDirectoryContent > files , InfoDownloadTaksModel idt = null ) // ItemsUploadedEventArgs<FileManagerDirectoryContent> args)
11321138 {
1139+ _logger . LogInformation ( "Adding upload task from server - DbName: {DbName}, Path: {Path}, FilesCount: {Count}" ,
1140+ dbName , currentPath , files . Count ) ;
11331141 idt = new InfoDownloadTaksModel ( ) ;
11341142 idt . tis = _tis ;
11351143 idt . id = Guid . NewGuid ( ) . ToString ( ) ;
@@ -1215,7 +1223,8 @@ public async Task<String> CreateStrmFiles(string path, string dbName, string hos
12151223 }
12161224 public async Task UploadFileFromServer ( string dbName , string currentPath , List < Syncfusion . Blazor . FileManager . FileManagerDirectoryContent > files , InfoDownloadTaksModel dm = null ) // ItemsUploadedEventArgs<FileManagerDirectoryContent> args)
12171225 {
1218-
1226+ _logger . LogInformation ( "Starting upload from server - DbName: {DbName}, Path: {Path}, FilesCount: {Count}" ,
1227+ dbName , currentPath , files . Count ) ;
12191228 // string currentPath = args.Path;
12201229 NotificationModel nm = new NotificationModel ( ) ;
12211230 InfoDownloadTaksModel idt = dm ;
@@ -1275,7 +1284,6 @@ public async Task UploadFileFromServer(string dbName, string currentPath, List<S
12751284 um . chatName = _ts . getChatName ( Convert . ToInt64 ( dbName ) ) ;
12761285 // add upload to task list
12771286 idt . addUpload ( um ) ;
1278- um . thread = Thread . CurrentThread ;
12791287 while ( attempts != 0 || um . state == StateTask . Canceled )
12801288 try
12811289 {
@@ -1292,7 +1300,8 @@ public async Task UploadFileFromServer(string dbName, string currentPath, List<S
12921300 _logger . LogInformation ( e , "Current work cancelled" ) ;
12931301 throw e ;
12941302 }
1295- _logger . LogError ( e , "Exception sending file to Telegram" ) ;
1303+ _logger . LogError ( e , "Exception sending file to Telegram - FileName: {FileName}, Attempt: {Attempt}, Remaining: {Remaining}" ,
1304+ file . Name , 4 - attempts , attempts - 1 ) ;
12961305 attempts -- ;
12971306 // waitForNextAttempt *= 2;
12981307 if ( attempts == 0 || um . state == StateTask . Canceled )
@@ -1305,6 +1314,7 @@ public async Task UploadFileFromServer(string dbName, string currentPath, List<S
13051314 um . state = StateTask . Error ;
13061315 throw e ;
13071316 }
1317+ _logger . LogWarning ( "Retrying upload in {DelayMs}ms - FileName: {FileName}" , waitForNextAttempt , file . Name ) ;
13081318 await Task . Delay ( waitForNextAttempt ) ;
13091319 }
13101320
@@ -1363,7 +1373,8 @@ public async Task UploadFileFromServer(string dbName, string currentPath, List<S
13631373 _logger . LogInformation ( e , "Current work cancelled" ) ;
13641374 throw e ;
13651375 }
1366- _logger . LogError ( e , "Exception sending file to Telegram" ) ;
1376+ _logger . LogError ( e , "Exception sending file to Telegram - FileName: {FileName}, Attempt: {Attempt}, Remaining: {Remaining}" ,
1377+ file . Name , 4 - attempts , attempts - 1 ) ;
13671378 attempts -- ;
13681379 // waitForNextAttempt *= 2;
13691380 if ( attempts == 0 || um . state == StateTask . Canceled )
@@ -1373,11 +1384,11 @@ public async Task UploadFileFromServer(string dbName, string currentPath, List<S
13731384 um . SendNotification ( ) ;
13741385 return ;
13751386 }
1376-
1387+
13771388 um . state = StateTask . Error ;
13781389 throw e ;
13791390 }
1380-
1391+ _logger . LogWarning ( "Retrying upload in {DelayMs}ms - FileName: {FileName}" , waitForNextAttempt , file . Name ) ;
13811392 await Task . Delay ( waitForNextAttempt ) ;
13821393 }
13831394
@@ -1432,9 +1443,8 @@ public async Task UploadFileFromServer(string dbName, string currentPath, List<S
14321443 return ;
14331444 }
14341445 idt . state = StateTask . Error ;
1435- _logger . LogError ( ex , $ "Error on uploadFileFromServer, path : { currentPath } " ) ;
1446+ _logger . LogError ( ex , "Error on uploadFileFromServer - Path: {Path}, Message : {Message}" , currentPath , ex . Message ) ;
14361447 nm . sendEvent ( new Notification ( "Error Uploading files to Telegram" , "Telegram Upload" , NotificationTypes . Error ) ) ;
1437- Console . WriteLine ( ex . Message ) ;
14381448 throw ex ;
14391449 }
14401450 }
@@ -1631,11 +1641,9 @@ public async Task UploadFile(string dbName, string currentPath, UploadFiles file
16311641 }
16321642 catch ( Exception ex )
16331643 {
1634- _logger . LogError ( ex , "Error on uploadFile" ) ;
1644+ _logger . LogError ( ex , "Error on uploadFile - FileName: {FileName}, Message: {Message}" , file . File . Name , ex . Message ) ;
16351645 NotificationModel nm = new NotificationModel ( ) ;
16361646 nm . sendEvent ( new Notification ( $ "Error on UploadFile: { file . File . Name } ", "Error" , NotificationTypes . Error ) ) ;
1637- Console . WriteLine ( ex . Message ) ;
1638-
16391647 throw ex ;
16401648 }
16411649 }
@@ -1855,6 +1863,8 @@ private async Task SaveToFile(IBrowserFile file, string path)
18551863
18561864 private async Task < List < string > > splitFileStreamAsync ( string path , string name , int splitSize )
18571865 {
1866+ _logger . LogInformation ( "Starting file split - FileName: {FileName}, SizeMB: {SizeMB:F2}, SplitSizeMB: {SplitSizeMB}" ,
1867+ name , new System . IO . FileInfo ( System . IO . Path . Combine ( path , name ) ) . Length / ( 1024.0 * 1024.0 ) , splitSize / ( 1024 * 1024 ) ) ;
18581868 int _gb = TelegramService . splitSizeGB ;
18591869 List < string > listPath = new List < string > ( ) ;
18601870 byte [ ] buffer = new byte [ splitSize ] ;
@@ -1864,7 +1874,6 @@ private async Task<List<string>> splitFileStreamAsync(string path, string name,
18641874 sm . name = name ;
18651875 sm . _size = fs . Length ;
18661876 sm . _transmitted = 0 ;
1867- sm . thread = Thread . CurrentThread ;
18681877 _tis . addToUploadList ( sm ) ;
18691878 int index = 1 ;
18701879 while ( fs . Position < fs . Length )
@@ -1892,12 +1901,13 @@ private async Task<List<string>> splitFileStreamAsync(string path, string name,
18921901 index ++ ;
18931902 }
18941903 }
1895-
1904+ _logger . LogInformation ( "File split completed - FileName: {FileName}, Parts: {PartsCount}" , name , listPath . Count ) ;
18961905 return listPath ;
18971906 }
18981907
18991908 private async Task mergeFileStreamAsync ( List < string > pathList , string destName )
19001909 {
1910+ _logger . LogInformation ( "Starting file merge - DestName: {DestName}, PartsCount: {PartsCount}" , destName , pathList . Count ) ;
19011911 using ( FileStream fileResult = new FileStream ( destName , FileMode . Create ) )
19021912 foreach ( string pathSplited in pathList )
19031913 {
@@ -1909,6 +1919,7 @@ private async Task mergeFileStreamAsync(List<string> pathList, string destName)
19091919 //await fileResult.WriteAsync(buffer);
19101920 }
19111921 }
1922+ _logger . LogInformation ( "File merge completed - DestName: {DestName}" , destName ) ;
19121923 }
19131924 }
19141925}
0 commit comments