Skip to main content

Microsoft.Extensions.Logging by Microsoft

Nuget / site data

Nuget GitHub last commit GitHub Repo stars

Details

Info

info

Original Readme

note

.NET Runtime

Build Status Help Wanted Gitter Discord

This repo contains the code to build the .NET runtime, libraries and shared host (dotnet) installers for all supported platforms, as well as the sources to .NET runtime and libraries.

What is .NET?

Official Starting Page: https://dotnet.microsoft.com

How can I contribute?

We welcome contributions! Many people all over the world have helped make this project better.

  • Contributing explains what kinds of contributions we welcome
  • Workflow Instructions explains how to build and test
  • Get Up and Running on .NET Core explains how to get nightly builds of the runtime and its libraries to test them in your own projects.

Reporting security issues and security bugs

Security issues and bugs should be reported privately, via email, to the Microsoft Security Response Center (MSRC) secure@microsoft.com. You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Further information, including the MSRC PGP key, can be found in the Security TechCenter. You can also find these instructions in this repo's Security doc.

Also see info about related Microsoft .NET Core and ASP.NET Core Bug Bounty Program.

Filing issues

This repo should contain issues that are tied to the runtime, the class libraries and frameworks, the installation of the dotnet binary (sometimes known as the muxer) and installation of the .NET runtime and libraries.

For other issues, please file them to their appropriate sibling repos. We have links to many of them on our new issue page.

.NET Foundation

.NET Runtime is a .NET Foundation project.

There are many .NET related projects on GitHub.

  • .NET home repo - links to 100s of .NET projects, from Microsoft and the community.
  • ASP.NET Core home - the best place to start learning about ASP.NET Core.

This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behavior in our community. For more information, see the .NET Foundation Code of Conduct.

General .NET OSS discussions: .NET Foundation Discussions

License

.NET (including the runtime repo) is licensed under the MIT license.

About

note

Logging defined and compiled

How to use

Example ( source csproj, source files )

This is the CSharp Project that references Microsoft.Extensions.Logging

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
</ItemGroup>
</Project>

Generated Files

Those are taken from $(BaseIntermediateOutputPath)\GX

// <auto-generated/>
#nullable enable

partial class LoggingSample
{
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Logging.Generators", "7.0.7.1805")]
private static readonly global::System.Action<global::Microsoft.Extensions.Logging.ILogger, global::System.Double, global::System.Exception?> __UsingFormatSpecifierCallback =
global::Microsoft.Extensions.Logging.LoggerMessage.Define<global::System.Double>(global::Microsoft.Extensions.Logging.LogLevel.Critical, new global::Microsoft.Extensions.Logging.EventId(20, nameof(UsingFormatSpecifier)), "Value is {value:E}", new global::Microsoft.Extensions.Logging.LogDefineOptions() { SkipEnabledCheck = true });

[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Logging.Generators", "7.0.7.1805")]
public static partial void UsingFormatSpecifier(global::Microsoft.Extensions.Logging.ILogger logger, global::System.Double value)
{
if (logger.IsEnabled(global::Microsoft.Extensions.Logging.LogLevel.Critical))
{
__UsingFormatSpecifierCallback(logger, value, null);
}
}
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Logging.Generators", "7.0.7.1805")]
private static readonly global::System.Action<global::Microsoft.Extensions.Logging.ILogger, global::System.Exception?> __LogWithCustomEventNameCallback =
global::Microsoft.Extensions.Logging.LoggerMessage.Define(global::Microsoft.Extensions.Logging.LogLevel.Trace, new global::Microsoft.Extensions.Logging.EventId(9, "CustomEventName"), "Fixed message", new global::Microsoft.Extensions.Logging.LogDefineOptions() { SkipEnabledCheck = true });

[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Logging.Generators", "7.0.7.1805")]
public partial void LogWithCustomEventName()
{
if (_logger.IsEnabled(global::Microsoft.Extensions.Logging.LogLevel.Trace))
{
__LogWithCustomEventNameCallback(_logger, null);
}
}
/// <summary> This API supports the logging infrastructure and is not intended to be used directly from your code. It is subject to change in the future. </summary>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Logging.Generators", "7.0.7.1805")]
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never)]
private readonly struct __LogWithDynamicLogLevelStruct : global::System.Collections.Generic.IReadOnlyList<global::System.Collections.Generic.KeyValuePair<string, object?>>
{
private readonly global::System.String _city;
private readonly global::System.String _province;

public __LogWithDynamicLogLevelStruct(global::System.String city, global::System.String province)
{
this._city = city;
this._province = province;

}

public override string ToString()
{
var city = this._city;
var province = this._province;

return $"Welcome to {city} {province}!";
}

public static readonly global::System.Func<__LogWithDynamicLogLevelStruct, global::System.Exception?, string> Format = (state, ex) => state.ToString();

public int Count => 3;

public global::System.Collections.Generic.KeyValuePair<string, object?> this[int index]
{
get => index switch
{
0 => new global::System.Collections.Generic.KeyValuePair<string, object?>("city", this._city),
1 => new global::System.Collections.Generic.KeyValuePair<string, object?>("province", this._province),
2 => new global::System.Collections.Generic.KeyValuePair<string, object?>("{OriginalFormat}", "Welcome to {city} {province}!"),

_ => throw new global::System.IndexOutOfRangeException(nameof(index)), // return the same exception LoggerMessage.Define returns in this case
};
}

public global::System.Collections.Generic.IEnumerator<global::System.Collections.Generic.KeyValuePair<string, object?>> GetEnumerator()
{
for (int i = 0; i < 3; i++)
{
yield return this[i];
}
}

global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => GetEnumerator();
}

[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Logging.Generators", "7.0.7.1805")]
public partial void LogWithDynamicLogLevel(global::System.String city, global::Microsoft.Extensions.Logging.LogLevel level, global::System.String province)
{
if (_logger.IsEnabled(level))
{
_logger.Log(
level,
new global::Microsoft.Extensions.Logging.EventId(10, nameof(LogWithDynamicLogLevel)),
new __LogWithDynamicLogLevelStruct(city, province),
null,
__LogWithDynamicLogLevelStruct.Format);
}
}
}

Usefull

Download Example (.NET C# )

Share Microsoft.Extensions.Logging

https://ignatandrei.github.io/RSCG_Examples/v2/docs/Microsoft.Extensions.Logging

In the same category (EnhancementClass) - 25 other generators

ApparatusAOT

AspectGenerator

CommonCodeGenerator

DudNet

Enhanced.GetTypes

FastGenericNew

HsuSgSync

Immutype

Ling.Audit

Lombok.NET

M31.FluentAPI

MemoryPack

Meziantou.Polyfill

Microsoft.Extensions.Options.Generators.OptionsValidatorGenerator

Microsoft.Interop.JavaScript.JSImportGenerator

OptionToStringGenerator

QueryStringGenerator

RSCG_Decorator

RSCG_UtilityTypes

StaticReflection

SyncMethodGenerator

System.Runtime.InteropServices

System.Text.RegularExpressions

TelemetryLogging

ThisClass