-
-
Save maryamariyan/4067efaee75831e3476bffda58f324f5 to your computer and use it in GitHub Desktop.
Logging Generator Sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<OutputType>Exe</OutputType> | |
<TargetFramework>net6.0</TargetFramework> | |
</PropertyGroup> | |
<ItemGroup> | |
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0-preview.4.21216.3" /> | |
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0-preview.4.21216.3" /> | |
</ItemGroup> | |
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.Extensions.Logging; | |
using Microsoft.Extensions.Logging.Console; | |
using Microsoft.Extensions.Logging.Abstractions; | |
using System; | |
namespace ConsoleApp66 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var logger = LoggerFactory.Create(builder => { builder.AddConsole(); }).CreateLogger("program"); | |
MyPoco.LogMethod(logger, LogLevel.Critical, "Lyanna", "LA"); | |
} | |
} | |
public partial class MyPoco | |
{ | |
public ILogger logger { get; set; } | |
[LoggerMessage(EventId = 2, Message = "Hello {name} from {city}")] | |
public static partial void LogMethod(ILogger logger, LogLevel logLevel, string name, string city); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Should the sample be update to use static methods, because of
?