当我在我的 F# 模块顶部包含 NLog.LogManager.GetCurrentClassLogger()
时,记录器的名称看起来类似于 <StartupCode$NLogTest>.$Program
。我希望得到类似于 NLogTest.TestModule
的更好的记录器名称。
我该如何为我的 F# 模块获取更好的记录器名称?
这里是一个完整的示例:
Program.fs
namespace NLogTest
type TestClass() =
let logger = NLog.LogManager.GetCurrentClassLogger()
member _.Run() =
logger.Info("Inside my class")
module TestModule =
let logger = NLog.LogManager.GetCurrentClassLogger()
let Run() =
logger.Info("Inside my module")
module Program =
[<EntryPoint>]
let Main _ =
TestClass().Run()
TestModule.Run()
0
NLogTest.fsproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<None Include="NLog.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<Compile Include="Program.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="NLog" Version="4.7.13" />
</ItemGroup>
</Project>
NLog.config
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="logconsole" xsi:type="Console" />
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="logconsole" />
</rules>
</nlog>
输出
2022-02-08 18:43:52.6678|INFO|NLogTest.TestClass|Inside my class
2022-02-08 18:43:52.6997|INFO|<StartupCode$NLogTest>.$Program|Inside my module
我希望改进的是最后一行。