Skip to content

Commit

Permalink
add logger
Browse files Browse the repository at this point in the history
  • Loading branch information
Tabing010102 committed Oct 16, 2023
1 parent 70d5fe5 commit 0eda802
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
11 changes: 6 additions & 5 deletions Librarian.Sephirah/Services/Binah/SimpleUploadFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Librarian.Common.Models;
using Librarian.Common.Utils;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Logging;
using Minio;
using Minio.DataModel.Args;
using System.Diagnostics;
Expand Down Expand Up @@ -30,14 +31,14 @@ public override async Task SimpleUploadFile(IAsyncStreamReader<SimpleUploadFileR
var pipeStreamClient4Minio = new AnonymousPipeClientStream(pipeStreamServer4Minio.GetClientHandleAsString());
//using var memoryStream = new MemoryStream();
//long receivedBytes = 0;
Debug.WriteLine($"SimpleUploadFile: Starting readTask");
_logger.LogDebug($"SimpleUploadFile: Starting readTask");
var readTask = Task.Run(async () =>
{
gameSaveFile.Status = GameSaveFileStatus.InProgress;
await _dbContext.SaveChangesAsync();
await foreach (var message in requestStream.ReadAllAsync())
{
Debug.WriteLine($"SimpleUploadFile: readTask message.Data.Length = {message.Data?.Length}");
_logger.LogDebug($"SimpleUploadFile: readTask message.Data.Length = {message.Data?.Length}");
if (message.Data != null)
{
//await memoryStream.WriteAsync(message.Data.Memory);
Expand All @@ -51,7 +52,7 @@ public override async Task SimpleUploadFile(IAsyncStreamReader<SimpleUploadFileR
pipeStreamServer4Minio.Close();
});
var writeTaskCancellationTokenSource = new CancellationTokenSource();
Debug.WriteLine($"SimpleUploadFile: Starting writeTask");
_logger.LogDebug($"SimpleUploadFile: Starting writeTask");
var writeTask = Task.Run(async () =>
{
long executionNum = 0;
Expand All @@ -76,11 +77,11 @@ public override async Task SimpleUploadFile(IAsyncStreamReader<SimpleUploadFileR
.WithStreamData(pipeStreamClient4Minio)
// https://youtu.be/V_T8x1n358U?t=348, set size = -1, take all
.WithObjectSize(-1);
Debug.WriteLine($"SimpleUploadFile: Starting minioPutTask");
_logger.LogDebug($"SimpleUploadFile: Starting minioPutTask");
var minioPutTask = _minioClient.PutObjectAsync(putObjectArgs);
// calc Sha256
using var sha256 = SHA256.Create();
Debug.WriteLine($"SimpleUploadFile: Starting sha256Task");
_logger.LogDebug($"SimpleUploadFile: Starting sha256Task");
var sha256Task = sha256.ComputeHashAsync(pipeStreamClient4Sha256);
// wait for readTask, minioPutTask, sha256Task
Task.WaitAll(readTask, minioPutTask, sha256Task);
Expand Down
5 changes: 4 additions & 1 deletion Librarian.Sephirah/Services/SephirahService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@
using Librarian.Angela.Services;
using Librarian.Common.Utils;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Logging;
using Minio;
using TuiHub.Protos.Librarian.Sephirah.V1;

namespace Librarian.Sephirah.Services
{
public partial class SephirahService : LibrarianSephirahService.LibrarianSephirahServiceBase
{
private readonly ILogger _logger;
private readonly ApplicationDbContext _dbContext;
private readonly PullMetadataService _pullMetadataService;
private readonly IMinioClient _minioClient;
public SephirahService(ApplicationDbContext dbContext, PullMetadataService pullMetadataService, IMinioClient minioClient)
public SephirahService(ILogger<SephirahService> logger ,ApplicationDbContext dbContext, PullMetadataService pullMetadataService, IMinioClient minioClient)
{
_logger = logger;
_dbContext = dbContext;
_pullMetadataService = pullMetadataService;
_minioClient = minioClient;
Expand Down

0 comments on commit 0eda802

Please sign in to comment.