ZoppaLoggingExtensions 1.0.3
dotnet add package ZoppaLoggingExtensions --version 1.0.3
NuGet\Install-Package ZoppaLoggingExtensions -Version 1.0.3
<PackageReference Include="ZoppaLoggingExtensions" Version="1.0.3" />
<PackageVersion Include="ZoppaLoggingExtensions" Version="1.0.3" />
<PackageReference Include="ZoppaLoggingExtensions" />
paket add ZoppaLoggingExtensions --version 1.0.3
#r "nuget: ZoppaLoggingExtensions, 1.0.3"
#:package ZoppaLoggingExtensions@1.0.3
#addin nuget:?package=ZoppaLoggingExtensions&version=1.0.3
#tool nuget:?package=ZoppaLoggingExtensions&version=1.0.3
説明
Microsoft.Extensions.Logging
に従って抽象化したログ出力機能を提供します。
これは、ZoppaDsqlを更新したZoppaDSqlMapperにおける標準ログ機能として使用されています。
高効率を目指していないため、ログ出力の効率を気にする場合は別のライブラリの使用を検討してください。
using Microsoft.Extensions.Logging;
using System.Runtime.InteropServices;
using ZoppaLoggingExtensions;
// ログ出力のためのファクトリを作成
using var loggerFactory = LoggerFactory.Create(builder => {
builder.AddZoppaLogging(
(config) => config.MinimumLogLevel = LogLevel.Trace
);
builder.SetMinimumLevel(LogLevel.Trace);
});
ILogger logger = loggerFactory.CreateLogger<Program>();
// ログ出力の例
using (logger.BeginScope("scope start {a}", 100)) {
logger.ZLog<Program>().LogDebug(1, "Does this line get hit? {h} {b}", 100, 200);
using (logger.ZLog<Program>().BeginScope("2")) {
logger.ZLog<Program>().LogDebug(3, "Nothing to see here.");
logger.ZLog<Program>().LogDebug(5, "Warning... that was odd.");
}
logger.ZLog<Program>().LogDebug(7, "Oops, there was an error.");
}
logger.ZLog<Program>().LogDebug(5, "== 120.");
Microsoft.Extensions.Logging
の初期化ルールに従い、ILoggingBuilder
に AddZoppaLogging
の拡張メソッドを使ってログの出力先の設定を行ってください。
AddZoppaLogging
には、ZoppaLoggingConfiguration
を設定するための Action<ZoppaLoggingConfiguration>
を渡すことができます。
ZoppaLoggingConfiguration
には、出力ファイルを指定する DefaultLogFile
と、カテゴリごとの出力ファイルを指定する LogFileByCategory
があります。
注意 ログレベルを指定する MinimumLogLevel
は ILoggingBuilder
の SetMinimumLevel
の値以上を指定するようにしてください。
汎用ホストを使用する例を以下に示します。
Private Shared Async Function MainAsync(args As String()) As Task
' 汎用ホストを作成
Dim builder = Microsoft.Extensions.Hosting.Host.CreateApplicationBuilder(args)
' 汎用ホストを使用して初期化
builder.Logging.ClearProviders()
builder.Logging.AddZoppaLogging(
Sub(config)
config.MinimumLogLevel = LogLevel.Trace
End Sub
)
builder.Logging.SetMinimumLevel(LogLevel.Trace)
' 汎用ホストをビルド、ログ出力
Using host = builder.Build()
Dim loggerFactory = host.Services.GetRequiredService(Of ILoggerFactory)()
Dim logger = loggerFactory.CreateLogger("Test")
logger.ZLog(Of Program).LogDebug(1, "Does this line get hit?")
logger.ZLog(Of Program).LogInformation(3, "Nothing to see here.")
logger.ZLog(Of Program).LogWarning(5, "Warning... that was odd.")
logger.ZLog(Of Program).LogError(7, "Oops, there was an error.")
logger.ZLog(Of Program).LogTrace(5, "== 120.")
Await host.RunAsync()
End Using
End Function
汎用ホストを使用する場合は、appsettings.json
で出力するファイルを指定することができます。
{
"Logging": {
"ZoppaLogging": {
"DefaultLogFile": "log.txt",
"LogFileByCategory": {
"Test": "test.txt"
}
}
}
}
最後に ILogger
の拡張メソッド ZLog
を使用すると呼び出し元のメソッド名と行番号を出力することができます。
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Extensions.Logging (>= 8.0.0)
- Microsoft.Extensions.Logging.Configuration (>= 8.0.0)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on ZoppaLoggingExtensions:
Package | Downloads |
---|---|
ZoppaDSqlMapper
Package Description |
|
ZoppaDSqlReplace
Package Description |
|
ZoppaDSqlCompiler
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.