Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
9 changes: 0 additions & 9 deletions .github/instructions/instructions.instructions.md

This file was deleted.

27 changes: 0 additions & 27 deletions .github/prompts/prompts.prompt.md

This file was deleted.

Empty file removed .github/scratch.md
Empty file.
20 changes: 4 additions & 16 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build the NuGet package
name: .NET

on:
workflow_dispatch:
Expand All @@ -11,10 +11,7 @@ jobs:
build:
name: Build and analyze
runs-on: windows-latest
env:
SONAR_PROJECT: astar-dev-logging-extensions
ProjectName: 'AStar.Dev.Logging.Extensions'
RepositoryName: 'astar-dev-logging-extensions'

steps:
- name: Set up JDK
uses: actions/[email protected]
Expand Down Expand Up @@ -49,23 +46,14 @@ jobs:
New-Item -Path .\.sonar\scanner -ItemType Directory
dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner

- name: 🔍 Restore, 🛠 Build and 🧪 Test with ☁️ SonarCloud / Qube
- name: 🔍 Restore, 🛠 Build and 🧪 Test with ☁️ SonarCloud / Qube project - ${{ vars.SONAR_PROJECT_NAME }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
shell: powershell
run: |
dotnet tool install --global dotnet-coverage
.\.sonar\scanner\dotnet-sonarscanner begin /k:"astar-development_${{ env.SONAR_PROJECT }}" /o:"astar-development" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml /d:sonar.scanner.scanAll=false /d:sonar.scanner.skipJreProvisioning=true
.\.sonar\scanner\dotnet-sonarscanner begin /k:"astar-development_${{ github.event.repository.name }}" /o:"astar-development" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml /d:sonar.scanner.scanAll=false /d:sonar.scanner.skipJreProvisioning=true
dotnet build --configuration Release
dotnet-coverage collect 'dotnet test --filter "FullyQualifiedName!~Tests.EndToEnd"' -f xml -o 'coverage.xml'
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"

- name: Pack NuGet package
if: github.ref == 'refs/heads/main'
run: dotnet pack .\src\${{ env.ProjectName }}\${{ env.ProjectName }}.csproj

- name: Push to NuGet
if: github.ref == 'refs/heads/main'
run: dotnet nuget push "**\${{ env.ProjectName }}.*.nupkg" --api-key ${{secrets.nuget_api_key}} --skip-duplicate --source https://api.nuget.org/v3/index.json

32 changes: 32 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: 🚀 Publish NuGet Package

on:
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read

steps:
- name: 🧾 Checkout code
uses: actions/checkout@v4

- name: 🛠 Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.x'

- name: 🔍 Restore dependencies
run: dotnet restore

- name: 🛠 Build solution
run: dotnet build --configuration Release

- name: 📦 Pack NuGet package for ${{ github.event.repository.name }}
run: dotnet pack ./src/**/*.csproj --configuration Release --output ./nupkg

- name: 🚀 Publish to NuGet.org
run: dotnet nuget push ./nupkg/*.nupkg --skip-duplicate --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NuGet_API_Key }} #

8 changes: 8 additions & 0 deletions .idea/.idea.AStar.Dev.Logging.Extensions/.idea/sonarlint.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions AStar.Dev.Logging.Extensions.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Solution>
<Folder Name="/.github/">
<File Path=".github/dependabot.yml"/>
</Folder>
<Folder Name="/.github/workflows/">
<File Path=".github/workflows/dotnet.yml"/>
</Folder>
<Folder Name="/Solution Items/">
<File Path="blog-draft.md"/>
</Folder>
<Folder Name="/src/">
<Project Path="src/AStar.Dev.Logging.Extensions/AStar.Dev.Logging.Extensions.csproj"/>
</Folder>
<Folder Name="/tests/">
<Project Path="tests/AStar.Dev.Logging.Extensions.Tests.Unit/AStar.Dev.Logging.Extensions.Tests.Unit.csproj"/>
</Folder>
</Solution>
Binary file removed AStar.png
Binary file not shown.
Binary file added astar.ico
Binary file not shown.
Binary file added astar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,50 @@

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<ApplicationIcon>astar.ico</ApplicationIcon>
<ImplicitUsings>enable</ImplicitUsings>
<AnalysisLevel>latest-recommended</AnalysisLevel>
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
</PropertyGroup>

<PropertyGroup>
<Authors>AStar Developement, Jason Barden</Authors>
<Company>AStar Development</Company>
<Copyright>AStar Developement, 2025</Copyright>
<PackageProjectUrl>https://github.com/astar-development/astar-dev-logging-extensions</PackageProjectUrl>
<RepositoryUrl>https://github.com/astar-development/astar-dev-logging-extensions.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<IncludeSymbols>True</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<PackageReadmeFile>Readme.md</PackageReadmeFile>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<Description>This package contains extension methods designed to add Serilog and Application Insights to the project. The logging is opinionated but the configuration can be overridden. In addition, Open Telemetry is being incorporated</Description>
<DocumentationFile>$(AssemblyName).xml</DocumentationFile>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>0.6.0</Version>
<Title>AStar.Dev.Logging.Extensions</Title>
<Description>This package contains extension methods designed to add Serilog and Application Insights to the project. The logging is opinionated but the configuration can be overridden.</Description>
<IncludeSymbols>true</IncludeSymbols>
<IsPackable>true</IsPackable>
<PackageIcon>astar.png</PackageIcon>
<PackageTags>Logging Application Insights Serilog LoggerMessage Templates</PackageTags>
<PackageId>AStar.Dev.Logging.Extensions</PackageId>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReadmeFile>Readme.md</PackageReadmeFile>
<PackageReleaseNotes>Add some LoggerMessage templates to cover the core use-cases</PackageReleaseNotes>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageTags>Logging Application Insights Serilog LoggerMessage Templates</PackageTags>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageProjectUrl>https://github.com/astar-development/astar-dev-logging-extensions</PackageProjectUrl>
<RepositoryUrl>https://github.com/astar-development/astar-dev-logging-extensions.git</RepositoryUrl>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<Title>AStar.Dev.Logging.Extensions</Title>
<Version>0.6.1</Version>
</PropertyGroup>

<ItemGroup>
<None Include="astar.png" Pack="true" PackagePath=""/>
<None Include="LICENSE" Pack="true" PackagePath=""/>
<None Include="Readme.md" Pack="true" PackagePath=""/>
<None Include="astar.png" Pack="true" PackagePath=""/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="AStar.Dev.Utilities" Version="1.6.2"/>
<PackageReference Include="AStar.Dev.Technical.Debt.Reporting" Version="0.2.1"/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="AStar.Dev.Utilities" Version="1.6.1"/>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.23.0"/>
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0"/>
<PackageReference Include="Serilog.Enrichers.Span" Version="3.1.0"/>
Expand Down
6 changes: 3 additions & 3 deletions src/AStar.Dev.Logging.Extensions/AStarLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public sealed class AStarLogger<TCategoryName>(ILogger<TCategoryName> logger, IT
public void LogPageView(string pageName)
{
ArgumentNullException.ThrowIfNull(pageName);
LogMessageTemplate.NotFound(logger, "/missing-resource");

logger.LogInformation(AStarEventIds.PageView, "Page view: {PageView}", pageName);
telemetryClient.TrackPageView(pageName);
}

Expand All @@ -25,6 +25,6 @@ public void LogPageView(string pageName)
public bool IsEnabled(LogLevel logLevel) => logger.IsEnabled(logLevel);

/// <inheritdoc />
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter) =>
logger.Log(logLevel, eventId, state, exception, formatter);
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
=> logger.Log(logLevel, eventId, state, exception, formatter);
}
8 changes: 8 additions & 0 deletions src/AStar.Dev.Logging.Extensions/LogMessageTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ namespace AStar.Dev.Logging.Extensions;
/// </summary>
public static partial class LogMessageTemplate
{
/// <summary>
/// Logs an informational message indicating that a specific page has been viewed.
/// </summary>
/// <param name="logger">The logger to be used for logging the event.</param>
/// <param name="pageName">The name of the page that was viewed.</param>
[LoggerMessage(EventId = 200, Level = LogLevel.Information, Message = "Page `{PageName}` viewed.")]
public static partial void PageView(ILogger logger, string pageName);

/// <summary>
/// Logs a warning message for a Bad Request (400) event, including the requested path.
/// </summary>
Expand Down
12 changes: 7 additions & 5 deletions src/AStar.Dev.Logging.Extensions/SerilogConfigure.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Globalization;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.Extensions.Configuration;
using Serilog;
Expand All @@ -16,9 +17,10 @@ internal static class SerilogConfigure
/// <param name="configuration">The application configuration settings to read from.</param>
/// <param name="telemetryConfiguration">The <see cref="TelemetryConfiguration" /> instance used for Application Insights integration.</param>
/// <returns>The configured instance of <see cref="LoggerConfiguration" />.</returns>
public static LoggerConfiguration Configure(this LoggerConfiguration loggerConfiguration, IConfiguration configuration, TelemetryConfiguration telemetryConfiguration) =>
loggerConfiguration
.WriteTo.ApplicationInsights(telemetryConfiguration,
TelemetryConverter.Traces).WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {Message:lj}{NewLine}{Exception}")
.ReadFrom.Configuration(configuration);
public static LoggerConfiguration Configure(this LoggerConfiguration loggerConfiguration, IConfiguration configuration, TelemetryConfiguration telemetryConfiguration)
=> loggerConfiguration
.WriteTo.ApplicationInsights(telemetryConfiguration,
TelemetryConverter.Traces).WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {Message:lj}{NewLine}{Exception}",
formatProvider: new CultureInfo(0809))
.ReadFrom.Configuration(configuration);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="AStar.Dev.Utilities" Version="1.6.1"/>
<PackageReference Include="AStar.Dev.Utilities" Version="1.6.2" />
<PackageReference Include="coverlet.collector" Version="6.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="JetBrains.Annotations" Version="2025.2.0"/>
<PackageReference Include="JetBrains.Annotations" Version="2025.2.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1"/>
<PackageReference Include="NSubstitute" Version="5.3.0"/>
<PackageReference Include="NSubstitute.Analyzers.CSharp" Version="1.0.17">
Expand Down
24 changes: 24 additions & 0 deletions tests/tests.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.2.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AStar.Dev.Logging.Extensions.Tests.Unit", "AStar.Dev.Logging.Extensions.Tests.Unit\AStar.Dev.Logging.Extensions.Tests.Unit.csproj", "{B632B798-552A-ABF4-C2EC-8BA23B67C816}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B632B798-552A-ABF4-C2EC-8BA23B67C816}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B632B798-552A-ABF4-C2EC-8BA23B67C816}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B632B798-552A-ABF4-C2EC-8BA23B67C816}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B632B798-552A-ABF4-C2EC-8BA23B67C816}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {43F8AC86-7006-4F6B-917D-64CCB494E87A}
EndGlobalSection
EndGlobal
Loading