MyCodeShow.LogLib 1.0.4

There is a newer version of this package available.
See the version list below for details.
dotnet add package MyCodeShow.LogLib --version 1.0.4
NuGet\Install-Package MyCodeShow.LogLib -Version 1.0.4
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MyCodeShow.LogLib" Version="1.0.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MyCodeShow.LogLib --version 1.0.4
#r "nuget: MyCodeShow.LogLib, 1.0.4"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install MyCodeShow.LogLib as a Cake Addin
#addin nuget:?package=MyCodeShow.LogLib&version=1.0.4

// Install MyCodeShow.LogLib as a Cake Tool
#tool nuget:?package=MyCodeShow.LogLib&version=1.0.4

LoggingDemo

This is a Central Logging App for My Code Show Website.

In the Library Project File(CSPROJ), first add the following items. This fixes Compiler Flags issue we see in Nuget Package Explorer.

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

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
    <IncludeSymbols>true</IncludeSymbols>
    <SymbolPackageFormat>snupkg</SymbolPackageFormat>
    <DebugType>portable</DebugType>
    <DebugSymbols>true</DebugSymbols>
    <EmbedAllSources>true</EmbedAllSources>
    <IsPackable>true</IsPackable>
    <EnableSourceLink>true</EnableSourceLink>
    <EmbedUntrackedSources>true</EmbedUntrackedSources>
    <GitRepositoryRemoteName>origin</GitRepositoryRemoteName>
    <PublishRepositoryUrl>true</PublishRepositoryUrl>
  </PropertyGroup>
  <PropertyGroup Condition="'$(BUILD_ARTIFACTSTAGINGDIRECTORY)' != ''">
    <ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
  </PropertyGroup>
  <PropertyGroup>
    <GeneratedNugetDir>.\nuget\</GeneratedNugetDir>
    <NuspecFile>$(GeneratedNugetDir)MyCodeShow.LogLib.nuspec</NuspecFile>
    <OutputPath>$(GeneratedNugetDir)</OutputPath>
    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
    <Nullable>annotations</Nullable>
  </PropertyGroup>
  <ItemGroup>
    <SourceRoot Include="$(MSBuildThisFileDirectory)/"/>
    <PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.0-beta-20204-02" PrivateAssets="All" />
    <PackageReference Include="MediatR" Version="9.0.0" />
    <PackageReference Include="Microsoft.ApplicationInsights" Version="2.18.0" />
    <PackageReference Include="Microsoft.ApplicationInsights.NLogTarget" Version="2.18.0" />
    <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
    <PackageReference Include="NLog" Version="4.7.10" />
    <PackageReference Include="NLog.Extensions.Logging" Version="1.7.3" />
  </ItemGroup>
  <ItemGroup>
    <None Update="Build\NLog.config">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Update="Build\NLog.xsd">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
  </ItemGroup>
</Project>

Create Nuget Folder. In this folder, create {packageId}.nuspec with following information.

<?xml version="1.0" encoding="utf-8" ?>
<package xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
    <id>MyCodeShow.LogLib</id>
    <title>MyCodeShow Website Logging Library</title>
    <version>1.0.2</version>
    <owners>MyCodeShow</owners>
    <authors>Sparta</authors>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <summary>MyCodeShow Website Logging Library</summary>
    <description>
          A Central Logging Library for MyCodeShow Website. 
          This library uses NLog and logs data to Azure App Insights.
    </description>
    <releaseNotes>MyCodeShow 1.0.2 - Fixed Compiler Flags and partly Source Link</releaseNotes>
    <language>en-US</language>
    <icon>logo.png</icon>
    <projectUrl>https://mycodeshow.dev/</projectUrl>
    <repository type="git" url="https://github.com/mycodeshow-dev/MyCodeShow.LogLib.git" branch="master" commit="e532d76927a5528f24da705a8e2431864d69b10f"/>
    <license type="expression">MIT</license>
    <tags>appinsights, logging lib</tags>
    <dependencies>
        <group targetFramework="net5.0">
        <dependency id="MediatR" version="9.0.0" exclude="Build,Analyzers" />
        <dependency id="Microsoft.ApplicationInsights" version="2.18.0" exclude="Build,Analyzers" />
        <dependency id="Microsoft.ApplicationInsights.NLogTarget" version="2.18.0" exclude="Build,Analyzers" />
        <dependency id="NLog" version="4.7.10" exclude="Build,Analyzers" />
        <dependency id="NLog.Extensions.Logging" version="1.7.3" exclude="Build,Analyzers" />
        <dependency id="Newtonsoft.Json" version="13.0.1" exclude="Build,Analyzers" />
      </group>
    </dependencies>
  </metadata>
  <files>
    <file src="logo.png" target="" />
    <file src="..\Build\**" target="build\" />
    <file src="..\MyCodeShow.LogLib.targets" target="build\" />
    <file src="..\bin\Debug\net5.0\MyCodeShow.LogLib.dll" target="lib\net5.0\MyCodeShow.LogLib.dll" />
  <file src="..\bin\Debug\net5.0\MyCodeShow.LogLib.pdb" target="lib\net5.0\MyCodeShow.LogLib.pdb" />
  </files>
</package>

The main thing to note in the above code is Files section. These file tags along with the following CSPROJ changes help in copying NLog.Config and NLog.xsd files to target project.

The above is used for creating proper Nuget Package. Below Part is used for Logging to Azure App Insights using NLOG Config file. Create a Build Folder and create NLog.config File in Build Folder.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" />
  </configSections>
  <nlog>
    <extensions>
      <add assembly="Microsoft.ApplicationInsights.NLogTarget" />
    </extensions>
    <targets>
      <target type="ApplicationInsightsTarget" name="aiTarget" >
        <instrumentationKey>xxxxxxxxxxxxxxxxxx</instrumentationKey>
        <contextproperty name="threadid" layout="${threadid}" />
      </target>
    </targets>
    <rules>
      <logger name="*" minlevel="Trace" writeTo="aiTarget" />
    </rules>
  </nlog>
</configuration>

NLog.xsd can be copied from the following site to the Build folder. http://www.nlog-project.org/schemas/NLog.xsd

Create a targets file with {packageid}.targets in the root project folder.

<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <None Include="$(MSBuildThisFileDirectory)\NLog.config">
      <Link>NLog.config</Link>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Include="$(MSBuildThisFileDirectory)\NLog.xsd">
      <Link>NLog.xsd</Link>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
  </ItemGroup>
</Project>

Then Build the project, and issue the following Command using Nuget CLI(https://www.nuget.org/downloads). Add the CLI to the environment variable. nuget add .{file}.nupkg -source C:\source\nuget_repo - Currently doing this is not creating proper Nuget files. Building the project is helping to create NUPKG file and SNUPKG file.

First Upload NUPKG file and then Upload SNUPKG file to Nuget. SNUPKG is symbols file.

While importing the package, in VS, enable these settings: image

image

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.6.2 350 8/25/2021
1.0.6 286 8/15/2021
1.0.5 269 8/15/2021
1.0.4 305 8/15/2021
1.0.3 278 8/15/2021
1.0.2 289 8/15/2021
1.0.1 454 8/15/2021

MyCodeShow 1.0.4 - Added Mediatr Logging Behavior Pipeline