Skip to content

Commit f7d3ac6

Browse files
committed
Updated NLog and simplified configuration
1 parent f8d9779 commit f7d3ac6

4 files changed

Lines changed: 37 additions & 15 deletions

File tree

samples/TestFtpServer/NLog.config

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
throwExceptions="false"
77
internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log" >
88

9+
<!-- enable asp.net core layout renderers -->
10+
<extensions>
11+
<add assembly="NLog.Web.AspNetCore"/>
12+
</extensions>
913

1014
<!-- optional, add some variabeles
1115
https://github.com/nlog/NLog/wiki/Configuration-file#variables
@@ -40,9 +44,14 @@
4044
Write all events with minimal level of Debug (So Debug, Info, Warn, Error and Fatal, but not Trace) to "f"
4145
<logger name="*" minlevel="Debug" writeTo="f" />
4246
-->
43-
<logger name="FubarDev.FtpServer.ConnectionHandlers.*" level="Trace" writeTo="null" final="true" />
44-
<logger name="FubarDev.FtpServer.FtpConnection:*" level="Trace" writeTo="null" final="true" />
45-
<logger name="FubarDev.FtpServer.Authentication.DefaultSslStreamWrapperFactory" level="Trace" writeTo="null" final="true" />
46-
<logger name="*" minlevel="Trace" writeTo="console" />
47+
<!--
48+
<logger name="FubarDev.FtpServer.ConnectionHandlers.*" final="true" />
49+
<logger name="FubarDev.FtpServer.FtpConnection:*" final="true" />
50+
<logger name="FubarDev.FtpServer.Authentication.DefaultSslStreamWrapperFactory" final="true" />
51+
<logger name="FubarDev.FtpServer.ServerCommandHandlers.TlsEnableServerCommandHandler" final="true" />
52+
-->
53+
<logger name="FubarDev.FtpServer.CommandHandlers.ListCommandHandler" minlevel="Trace" writeTo="console" final="true" />
54+
<logger name="FubarDev.FtpServer.CommandHandlers.MlstCommandHandler" minlevel="Trace" writeTo="console" final="true" />
55+
<logger name="*" minlevel="Debug" writeTo="console" />
4756
</rules>
4857
</nlog>

samples/TestFtpServer/Program.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
using Microsoft.Extensions.Hosting;
1313
using Microsoft.Extensions.Logging;
1414

15-
using NLog.Extensions.Logging;
15+
using NLog.Web;
1616

1717
using TestFtpServer.Configuration;
1818

@@ -26,6 +26,8 @@ private static async Task<int> Main(string[] args)
2626
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),
2727
"SharpFtpServer");
2828

29+
NLog.LogManager.LoadConfiguration("NLog.config");
30+
2931
var hostBuilder = new HostBuilder()
3032
.UseConsoleLifetime()
3133
.ConfigureHostConfiguration(
@@ -40,21 +42,17 @@ private static async Task<int> Main(string[] args)
4042
$"appsettings.{hostContext.HostingEnvironment.EnvironmentName}.json",
4143
optional: true)
4244
.AddJsonFile(
43-
Path.Combine(configPath, $"appsettings.{hostContext.HostingEnvironment.EnvironmentName}.json"),
45+
Path.Combine(
46+
configPath,
47+
$"appsettings.{hostContext.HostingEnvironment.EnvironmentName}.json"),
4448
optional: true)
4549
.AddEnvironmentVariables("FTPSERVER_")
4650
.Add(new OptionsConfigSource(args));
4751
})
4852
.ConfigureLogging(
4953
(hostContext, loggingBuilder) =>
5054
{
51-
loggingBuilder.AddNLog(
52-
new NLogProviderOptions
53-
{
54-
CaptureMessageTemplates = true,
55-
CaptureMessageProperties = true,
56-
});
57-
NLog.LogManager.LoadConfiguration("NLog.config");
55+
loggingBuilder.ClearProviders();
5856
})
5957
.ConfigureServices(
6058
(hostContext, services) =>
@@ -68,6 +66,12 @@ private static async Task<int> Main(string[] args)
6866
.AddFtpServices(options)
6967
.AddHostedService<HostedFtpService>()
7068
.AddSingleton<ServerShell>();
69+
})
70+
.UseNLog(
71+
new NLogAspNetCoreOptions()
72+
{
73+
CaptureMessageTemplates = true,
74+
CaptureMessageProperties = true,
7175
});
7276

7377
try

samples/TestFtpServer/TestFtpServer.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.2.0" />
1616
<PackageReference Include="Microsoft.Extensions.Options" Version="2.2.0" />
1717
<PackageReference Include="Nito.AsyncEx.Context" Version="5.0.0" />
18-
<PackageReference Include="NLog" Version="4.6.4" />
19-
<PackageReference Include="NLog.Extensions.Logging" Version="1.5.0" />
18+
<PackageReference Include="NLog" Version="4.6.5" />
19+
<PackageReference Include="NLog.Web.AspNetCore" Version="4.8.3" />
2020
<PackageReference Include="Portable.BouncyCastle" Version="1.8.5" />
2121
<PackageReference Include="ReadLine" Version="2.0.1" />
2222
</ItemGroup>

samples/TestFtpServer/appsettings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
{
2+
"Logging": {
3+
"IncludeScopes": false,
4+
"LogLevel": {
5+
"Default": "Debug",
6+
"Microsoft": "Information",
7+
"FubarDev.FtpServer.CommandHandlers.ListCommandHandler": "Trace"
8+
}
9+
},
10+
211
/* Supported authentication types are: "custom","anonymous", "pam", "default".
312
* "default" means "not set" and is equal to "anonymous". */
413
"authentication": "default",

0 commit comments

Comments
 (0)