Commit 1d8619b3 authored by alan.f's avatar alan.f

add-serlog-config

parent bca58d5e
......@@ -19,9 +19,13 @@ RUN dotnet restore "ExchangeService.Client.csproj"
RUN dotnet build -c Release -o /app2
WORKDIR "/src/ExchangeService.Test"
RUN dotnet restore "ExchangeService.Test.csproj"
RUN dotnet restore "UnitTest/ExchangeServiceClient.Test.csproj"
RUN dotnet build -c Release -o /app3
WORKDIR "/src/ExchangeService.Test"
RUN dotnet restore "UnitTest/ExchangeServiceGrpcServer.Test.csproj"
RUN dotnet build -c Release -o /app4
FROM base AS final
WORKDIR /app
......
......@@ -17,8 +17,9 @@ using Serilog;
namespace ExchangeService.Client.Controllers
{
[Route("api/[controller]")]
[ApiController]
[Route("[controller]")]
public class DicomTransferFileController : ControllerBase
{
#region Properties
......@@ -42,6 +43,8 @@ namespace ExchangeService.Client.Controllers
[HttpPost]
public async Task Post([FromForm]Models.FilesPackage queryFilters)
{
Log.Information("DicomTransferFile Started ...!");
SendCallback sc = new SendCallback();
string connectionString = _configuration.GetConnectionString("DefaultConnection");
string view = _configuration["Views:ImageDetails"];
......@@ -65,7 +68,7 @@ namespace ExchangeService.Client.Controllers
});
});
var channel = GrpcChannel.ForAddress("https://localhost:8098");
var channel = GrpcChannel.ForAddress("https://localhost:5001");
var client =new DicomOps.DicomOpsClient(channel);
_uploadedFiles.ToObservable().Subscribe(uploadedFile =>
{
......@@ -85,7 +88,7 @@ namespace ExchangeService.Client.Controllers
Log.Error("There is no file to send");
sc.OnOperationFailed();
}
Log.Information("operation successed!");
Log.Information("operation Finished!");
sc.OnSendingFinished();
}
#endregion
......
......@@ -3,6 +3,7 @@ using ExchangeService.Client.Models;
using ExchangeService.GrpcServer;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Serilog;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
......@@ -28,6 +29,7 @@ namespace DicomTransferFileApi.Client.Controllers
[HttpPost]
public async Task<List<DicomFilesTransferModel>> Post([FromForm]ExchangeService.Client.Models.FilesPackage inputsDto)
{
Log.Information("FindDicomFile Started ...!");
string connectionString = configuration != null ? configuration.GetConnectionString("DefaultConnection") :
"Data Source=localhost;Integrated Security=SSPI;Initial Catalog=mv";
string view = configuration != null ? configuration["Views:ImageDetails"] : "vw_image_details";
......
......@@ -27,6 +27,7 @@
<PackageReference Include="Serilog.Extensions.Logging" Version="3.0.1" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
<PackageReference Include="Serilog.Sinks.File" Version="4.1.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.5.1" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.2" />
<PackageReference Include="System.Reactive" Version="4.4.1" />
</ItemGroup>
......
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ActiveDebugProfile>Docker</ActiveDebugProfile>
<ActiveDebugProfile>IIS Express</ActiveDebugProfile>
</PropertyGroup>
</Project>
\ No newline at end of file
......@@ -22,13 +22,6 @@
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:5001;http://localhost:5000"
},
"Docker": {
"commandName": "Docker",
"launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
"publishAllPorts": true,
"useSSL": true
}
}
}
\ No newline at end of file
......@@ -42,7 +42,7 @@ namespace ExchangeService.Client.SerilogConfig
.MinimumLevel.ControlledBy(levelSwitch)
.Enrich.WithCaller()
.WriteTo.Console(outputTemplate: @"time=""{Timestamp:HH:mm:ss.fff}"" app=""{App}"" action=""{Action}"" level=""{Level:u3}"" msg=""{Message}""{NewLine:l}{Exception:l}")
.WriteTo.File(@"c:\log\msrcore-client.txt", outputTemplate: @"time=""{Timestamp:HH:mm:ss.fff}"" app=""{App}"" action=""{Action}"" level=""{Level:u3}"" msg=""{Message}""{NewLine:l}{Exception:l}",
.WriteTo.File(@"d:\logs\msrcore-client.txt", outputTemplate: @"time=""{Timestamp:HH:mm:ss.fff}"" app=""{App}"" action=""{Action}"" level=""{Level:u3}"" msg=""{Message}""{NewLine:l}{Exception:l}",
fileSizeLimitBytes: 10485760,
rollingInterval: RollingInterval.Day, shared: true,
rollOnFileSizeLimit: true);
......
......@@ -24,6 +24,8 @@ namespace ExchangeService.Client
public void ConfigureServices(IServiceCollection services)
{
services.AddRazorPages();
services.AddControllers();
services.AddSwaggerGen();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
......@@ -39,7 +41,11 @@ namespace ExchangeService.Client
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
});
app.UseHttpsRedirection();
app.UseStaticFiles();
......
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ActiveDebugProfile>Docker</ActiveDebugProfile>
<ActiveDebugProfile>ExchangeService.GrpcServer</ActiveDebugProfile>
</PropertyGroup>
</Project>
\ No newline at end of file
......@@ -14,17 +14,7 @@ namespace ExchangeService.GrpcServer
{
public static void Main(string[] args)
{
var resp = SeriLogConfig.LoggerConfiguration(Serilog.Events.LogEventLevel.Debug);
if (!resp.Result)
{
Console.WriteLine(resp.Log);
return;
}
SeriLogConfig.LoggerConfiguration(Serilog.Events.LogEventLevel.Information);
Log.Information("Starting ExchangeService.GrpcServer ...");
CreateHostBuilder(args).Build().Run();
}
......
......@@ -42,7 +42,7 @@ namespace ExchangeService.GrpcServer.SerilogConfig
.MinimumLevel.ControlledBy(levelSwitch)
.Enrich.WithCaller()
.WriteTo.Console(outputTemplate: @"time=""{Timestamp:HH:mm:ss.fff}"" app=""{App}"" action=""{Action}"" level=""{Level:u3}"" msg=""{Message}""{NewLine:l}{Exception:l}")
.WriteTo.File(@"c:\log\msrcore-server.txt", outputTemplate: @"time=""{Timestamp:HH:mm:ss.fff}"" app=""{App}"" action=""{Action}"" level=""{Level:u3}"" msg=""{Message}""{NewLine:l}{Exception:l}",
.WriteTo.File(@"d:\logs\msrcore-server.txt", outputTemplate: @"time=""{Timestamp:HH:mm:ss.fff}"" app=""{App}"" action=""{Action}"" level=""{Level:u3}"" msg=""{Message}""{NewLine:l}{Exception:l}",
fileSizeLimitBytes: 10485760,
rollingInterval: RollingInterval.Day, shared: true,
rollOnFileSizeLimit: true);
......
......@@ -3,22 +3,19 @@ using System.Threading.Tasks;
using Dicom.Network;
using Grpc.Core;
using Microsoft.Extensions.Logging;
using Serilog;
using DicomClient = Dicom.Network.Client.DicomClient;
namespace ExchangeService.GrpcServer
{
public class DicomFileOperationService : DicomOps.DicomOpsBase
{
private readonly ILogger _logger;
public DicomFileOperationService(ILoggerFactory loggerFactory)
{
_logger = loggerFactory.CreateLogger<DicomFileOperationService>();
}
public override async Task TransferDicomFiles(DicomFilesTransferModel request,
IServerStreamWriter<DicomFilesTransferResponse> responseStream,
ServerCallContext context)
{
Log.Information("DicomTransferFile Started ...!");
var client = new DicomClient("127.0.0.1", 104, false, "MARCO", "ANY-SCP");
//var client = new DicomClient(request.ServerHost, request.Port, false, request.ServerAET, request.Aet);
client.NegotiateAsyncOps();
......@@ -29,11 +26,16 @@ namespace ExchangeService.GrpcServer
await client.AddRequestAsync(requests);
await client.SendAsync();
await responseStream.WriteAsync(new DicomFilesTransferResponse() { Message = $" {request.UploadedFile} file Send" });
Log.Information($" {request.UploadedFile} file Send" );
}
catch (Exception ex)
{
Log.Information(ex.Message);
await responseStream.WriteAsync(new DicomFilesTransferResponse() { Message = ex.Message });
}
Log.Information("DicomTransferFile Finished ...!");
}
}
}
......@@ -2,11 +2,13 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using ExchangeService.GrpcServer.SerilogConfig;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Serilog;
namespace ExchangeService.GrpcServer
{
......@@ -38,6 +40,18 @@ namespace ExchangeService.GrpcServer
await context.Response.WriteAsync("Communication with gRPC endpoints must be made through a gRPC client. To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909");
});
});
var resp = SeriLogConfig.LoggerConfiguration(Serilog.Events.LogEventLevel.Debug);
if (!resp.Result)
{
Console.WriteLine(resp.Log);
return;
}
SeriLogConfig.LoggerConfiguration(Serilog.Events.LogEventLevel.Information);
Log.Information("Starting ExchangeService.GrpcServer ...");
}
}
}
......@@ -15,7 +15,7 @@ namespace ExchangeServiceGrpcServer.Test
{
// Arrange
var service = new DicomFileOperationService(NullLoggerFactory.Instance);
var service = new DicomFileOperationService();
string uploadedFile = "D:\\Study\\0095.07.24\\Anonymized (2)\\SR 1\\IM00001.dcm";
var cts = new CancellationTokenSource();
var callContext = TestServerCallContext.Create(cancellationToken: cts.Token);
......@@ -34,7 +34,7 @@ namespace ExchangeServiceGrpcServer.Test
{
// Arrange
var service = new DicomFileOperationService(NullLoggerFactory.Instance);
var service = new DicomFileOperationService();
List<string> uploadedFiles =new List<string>()
{
"D:\\Study\\0095.07.24\\Anonymized (2)\\SR 1\\IM00001.dcm",
......@@ -62,7 +62,7 @@ namespace ExchangeServiceGrpcServer.Test
{
// Arrange
var service = new DicomFileOperationService(NullLoggerFactory.Instance);
var service = new DicomFileOperationService();
List<string> uploadedFiles = new List<string>()
{
"D:\\Study\\0095.07.24\\Anonymized (2)\\SR 1\\IM00001.dcm",
......@@ -98,7 +98,7 @@ namespace ExchangeServiceGrpcServer.Test
{
// Arrange
var service = new DicomFileOperationService(NullLoggerFactory.Instance);
var service = new DicomFileOperationService();
string uploadedFile = "D:\\Study\\0095.07.24\\Anonymized (2)\\SR 1\\IM900001.dcm";
var cts = new CancellationTokenSource();
var callContext = TestServerCallContext.Create(cancellationToken: cts.Token);
......@@ -117,7 +117,7 @@ namespace ExchangeServiceGrpcServer.Test
{
// Arrange
var service = new DicomFileOperationService(NullLoggerFactory.Instance);
var service = new DicomFileOperationService();
var cts = new CancellationTokenSource();
var callContext = TestServerCallContext.Create(cancellationToken: cts.Token);
var responseStream = new TestServerStreamWriter<DicomFilesTransferResponse>(callContext);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment