Skip to content

[automated] Merge branch 'main' => 'dev' #687

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 26 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
863b1e3
Update dependencies from https://github.com/dotnet/extensions build 2…
dotnet-maestro[bot] Feb 18, 2025
5d38a29
[main] Update dependencies from dotnet/extensions (#655)
dotnet-maestro[bot] Feb 23, 2025
4b9a2b7
Update dependencies from https://github.com/dotnet/extensions build 2…
dotnet-maestro[bot] Feb 25, 2025
00cab3f
[main] Update dependencies from dotnet/extensions (#660)
dotnet-maestro[bot] Feb 27, 2025
84caabe
[main] Update dependencies from dotnet/extensions (#661)
dotnet-maestro[bot] Mar 3, 2025
0681667
Update dependencies from https://github.com/dotnet/extensions build 2…
dotnet-maestro[bot] Mar 3, 2025
cc28c07
Update dependencies from https://github.com/dotnet/extensions build 2…
dotnet-maestro[bot] Mar 4, 2025
5942ff2
Update dependencies from https://github.com/dotnet/extensions build 2…
dotnet-maestro[bot] Mar 5, 2025
4c01d3e
Update dependencies from https://github.com/dotnet/extensions build 2…
dotnet-maestro[bot] Mar 6, 2025
3a6b342
[main] Update dependencies from dotnet/extensions (#667)
dotnet-maestro[bot] Mar 12, 2025
94351a4
Update dependencies from https://github.com/dotnet/arcade build 20250…
dotnet-maestro[bot] Mar 13, 2025
412fd8b
Update dependencies from https://github.com/dotnet/extensions build 2…
dotnet-maestro[bot] Mar 13, 2025
81e89bf
Update dependencies from https://github.com/dotnet/extensions build 2…
dotnet-maestro[bot] Mar 14, 2025
67b0edb
Update dependencies from https://github.com/dotnet/extensions build 2…
dotnet-maestro[bot] Mar 15, 2025
5de37cb
Update dependencies from https://github.com/dotnet/arcade build 20250…
dotnet-maestro[bot] Mar 17, 2025
a98b9c6
Update dependencies from https://github.com/dotnet/extensions build 2…
dotnet-maestro[bot] Mar 18, 2025
8f8ae22
Update dependencies from https://github.com/dotnet/extensions build 2…
dotnet-maestro[bot] Mar 19, 2025
b02b4a0
Update dependencies from https://github.com/dotnet/extensions build 2…
dotnet-maestro[bot] Mar 20, 2025
4064d90
Update dependencies from https://github.com/dotnet/extensions build 2…
dotnet-maestro[bot] Mar 21, 2025
0a39c7a
Update dependencies from https://github.com/dotnet/extensions build 2…
dotnet-maestro[bot] Mar 22, 2025
f5ea9dc
Update dependencies from https://github.com/dotnet/extensions build 2…
dotnet-maestro[bot] Mar 24, 2025
7d3da3a
Update dependencies from https://github.com/dotnet/extensions build 2…
dotnet-maestro[bot] Mar 25, 2025
5ef1e8f
Initial commit
Mar 25, 2025
2ba36ca
Merge pull request #686 from evgenyfedorov2/users/evgenyfedorov2/rand…
evgenyfedorov2 Mar 25, 2025
a53436d
Update dependencies from https://github.com/dotnet/extensions build 2…
dotnet-maestro[bot] Mar 26, 2025
caee56b
Merge branch 'dev' into merge/main-to-dev
RussKie Mar 26, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Samples.sln
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Compliance", "Compliance",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AuditReports", "src\Compliance\AuditReports\AuditReports.csproj", "{9B5FB8C7-27BA-4397-B4B8-DD0B0D525CB2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LogSampling", "src\Telemetry\Logging\LogSampling\LogSampling.csproj", "{1A8652E7-EA1D-49AF-98B3-56D655F759B6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -93,6 +95,10 @@ Global
{9B5FB8C7-27BA-4397-B4B8-DD0B0D525CB2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9B5FB8C7-27BA-4397-B4B8-DD0B0D525CB2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9B5FB8C7-27BA-4397-B4B8-DD0B0D525CB2}.Release|Any CPU.Build.0 = Release|Any CPU
{1A8652E7-EA1D-49AF-98B3-56D655F759B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1A8652E7-EA1D-49AF-98B3-56D655F759B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1A8652E7-EA1D-49AF-98B3-56D655F759B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1A8652E7-EA1D-49AF-98B3-56D655F759B6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -116,6 +122,7 @@ Global
{931A6585-1085-4185-AE12-78BBA87F2A73} = {175F98E5-AFE8-4978-A512-EB84AD660208}
{C42F13CB-E8D9-4A37-BFCC-A50458509D69} = {301296EC-54FF-4ADC-B2D1-281E0C7F2867}
{9B5FB8C7-27BA-4397-B4B8-DD0B0D525CB2} = {C42F13CB-E8D9-4A37-BFCC-A50458509D69}
{1A8652E7-EA1D-49AF-98B3-56D655F759B6} = {248CB37C-2412-4231-96C0-092413C10D4B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6083D400-BF26-4ACE-86A8-778D26A8FA6A}
Expand Down
16 changes: 16 additions & 0 deletions src/Telemetry/Logging/LogSampling/Log.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.Extensions.Logging;

namespace LogSampling;

internal static partial class Log
{
[LoggerMessage(Level = LogLevel.Error, Message = "ERROR log message in my application.")]
public static partial void ErrorMessage(ILogger logger);

[LoggerMessage(Level = LogLevel.Information, Message = "INFORMATION log message in my application.")]
public static partial void InformationMessage(ILogger logger);

}
21 changes: 21 additions & 0 deletions src/Telemetry/Logging/LogSampling/LogSampling.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Description>Demonstrates how to use log sampling feature.</Description>
<OutputType>Exe</OutputType>
<NoWarn>$(NoWarn);EXTEXP0003</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="$(MicrosoftExtensionsLoggingConsoleVersion)" />
<PackageReference Include="Microsoft.Extensions.Telemetry" Version="9.4.0-preview.1.25174.4" />
</ItemGroup>

<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
41 changes: 41 additions & 0 deletions src/Telemetry/Logging/LogSampling/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Threading;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace LogSampling;

internal static class Program
{
public static void Main()
{
var hostBuilder = Host.CreateApplicationBuilder();
hostBuilder.Logging.AddSimpleConsole(options =>
{
options.SingleLine = true;
options.TimestampFormat = "hh:mm:ss";
});

// Add the Random probabilistic sampler to the logging pipeline.
hostBuilder.Logging.AddRandomProbabilisticSampler(hostBuilder.Configuration);

var app = hostBuilder.Build();
var loggerFactory = app.Services.GetRequiredService<ILoggerFactory>();
var logger = loggerFactory.CreateLogger("SamplingDemo");

// Simulate a prod application with many log messages generated:
while (true)
{
Log.ErrorMessage(logger);

for (int i = 0; i < 10; i++)
{
Log.InformationMessage(logger);
Thread.Sleep(300);
}
}
}
}
20 changes: 20 additions & 0 deletions src/Telemetry/Logging/LogSampling/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Log Sampling

This sample shows how to use
[log sampling](https://github.com/dotnet/extensions/blob/main/src/Libraries/Microsoft.Extensions.Telemetry/README.md).
Log Sampling allows logs to be sampled, e.g. only some share of all log messages will be emitted.

The sample uses a typical `HostApplicationBuilder` pattern to configure a small console application with
logging. Log sampling is enabled by calling `.AddRandomProbabilisticSampler()` on the logging builder
and
providing a configuration via `appsettings.json`.

The configuration in `appsettings.json` is flexible - you can configure specific sampling rates per
any combination of
- log level
- category name
- event id

And, importantly, the configuration supports dynamic runtime updates via the `IOptionsMonitor<T>` pattern.
So you can change the `appsettings.json` (in the `/artifacts/bin/LogSampling/Debug` folder) at runtime
and the changes will be picked up by the Log sampling.
20 changes: 20 additions & 0 deletions src/Telemetry/Logging/LogSampling/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"Logging": {
"LogLevel": {
"Default": "Information"
}
},

"RandomProbabilisticSampler": {
"Rules": [
{
"LogLevel": "Information",
"Probability": 1
},
{
"LogLevel": "Error",
"Probability": 1
}
]
}
}
Loading