问题
I see in files like this within the Microsoft Owin projects a logger is being called
https://github.com/aspnet/AspNetKatana/blob/dev/src/Microsoft.Owin.Security.OpenIdConnect/OpenidConnectAuthenticationHandler.cs
Can anyone tell me how I activate it to actually start writing logs somewhere that I can read?
回答1:
By default Katana uses the TraceSource mechanism in .NET for logging. Add the following snippet to your config file to enable logging to a file:
<system.diagnostics>
<trace autoflush="true" />
<sources>
<source name="Microsoft.Owin">
<listeners>
<add name="KatanaListener" />
</listeners>
</source>
</sources>
<sharedListeners>
<add name="KatanaListener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="katana.trace.log"
traceOutputOptions="ProcessId, DateTime" />
</sharedListeners>
<switches>
<add name="Microsoft.Owin"
value="Verbose" />
</switches>
</system.diagnostics>
You can use Katana's default logging infrastructure and modify as needed. Here is a very detailed post that explains Katana's logging infrastructure and outlines how to add Owin/Katana logging to your projects. It also contains Github samples that you can reference.
This official Microsoft guide is very helpful as well.
来源:https://stackoverflow.com/questions/51283208/how-do-i-use-owin-katana-logger