2
我無法讓我的F#項目寫入TraceSource。.NET Core F#項目不會寫入TraceSource
這裏是我的F#代碼:
use logFileStream = new FileStream("log.txt", FileMode.Append, FileAccess.Write)
(
use logFileListener = new TextWriterTraceListener(logFileStream)
(
let traceSource = TraceSource("Test", SourceLevels.All)
traceSource.Listeners.Add(logFileListener) |> ignore
traceSource.TraceEvent(TraceEventType.Verbose, 1, "This is a test.")
)
)
這裏是我的F#項目:
<Project Sdk="FSharp.NET.Sdk;Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="FSharp.Core" Version="4.1.*" />
<PackageReference Include="FSharp.NET.Sdk" Version="1.0.*" PrivateAssets="All" />
<PackageReference Include="System.Diagnostics.TextWriterTraceListener" Version="4.3.0" />
<PackageReference Include="System.Diagnostics.Tracing" Version="4.3.0" />
</ItemGroup>
</Project>
爲什麼log.txt的空?