--- lang: ja-jp breaks: true --- # .NET Core でのロギング C# 2021-04-19 > .NET Core および ASP.NET Core でのログ記録 > https://docs.microsoft.com/ja-jp/aspnet/core/fundamentals/logging/?view=aspnetcore-5.0 .NET Core でのロギングのサンプル > dotnet/AspNetCore.Docs https://github.com/dotnet/AspNetCore.Docs/tree/main/aspnetcore/fundamentals/logging/index/samples/3.x ## ログをファイルに出力したい場合は、NLogを使用する。 * Visual Studio 2019 * NLog 4.7.9 > .net Core 3.1 の NLogではまった… その1 > https://blog.goo.ne.jp/pianyi/e/63d643b66739ea286e74bac9b39b5c2a ### プロジェクト直下に「NLog.config」ファイルを作成して、「新しい場合はコピーする」設定に変更する。 ※50Mbyteでローテーションする設定。 ```xml= <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd" autoReload="true" throwExceptions="false" internalLogLevel="Off" internalLogFile="${basedir}/logs/nlog-internal.log"> <targets> <target xsi:type="Debugger" name="LogConsole" layout="${longdate} [${uppercase:${level:padding=-5}}] ${message} ${exception:format=Message, Type, ToString:separator=\r\n}" /> <target xsi:type="File" name="LogFile" fileName="${basedir}/logs/aiueo.log" encoding="UTF-8" lineEnding="CRLF" archiveFileName="${basedir}/logs/aiueo_{#}.zip" archiveEvery="Day" archiveNumbering="DateAndSequence" archiveDateFormat="yyyyMMdd" archiveAboveSize="50000000" maxArchiveFiles="10" enableArchiveFileCompression="true" layout="${longdate} [${threadid:padding=8}] [${uppercase:${level:padding=-5}}] ${message} ${exception:format=Message, Type, ToString:separator=\r\n}" /> </targets> <rules> <logger name="*" minlevel="Debug" writeTo="LogConsole" /> <logger name="*" minlevel="Debug" writeTo="LogFile" /> </rules> </nlog> ```  以上の設定で、アプリケーションと同じディレクトリにログファイルが出力される。 ###### tags: `.NET Core` `NLog` `C#` `ログ出力` `ロギング`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up