MyCodeShow.LogLib 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package MyCodeShow.LogLib --version 1.0.1
                    
NuGet\Install-Package MyCodeShow.LogLib -Version 1.0.1
                    
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.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MyCodeShow.LogLib" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="MyCodeShow.LogLib" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MyCodeShow.LogLib --version 1.0.1
                    
#r "nuget: MyCodeShow.LogLib, 1.0.1"
                    
#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.
#:package MyCodeShow.LogLib@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MyCodeShow.LogLib&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=MyCodeShow.LogLib&version=1.0.1
                    
Install as a Cake Tool

LoggingDemo

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

In the Library Project File(CSPROJ), first add the following items. This should enable Source Link.

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

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
    <AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
    <SymbolPackageFormat>snupkg</SymbolPackageFormat>
    <DebugType>embedded</DebugType>
    <DebugSymbols>true</DebugSymbols>
    <EmbedAllSources>true</EmbedAllSources>
    <IsPackable>true</IsPackable>
    <EnableSourceLink>true</EnableSourceLink>
  </PropertyGroup>
  <PropertyGroup>
    <GeneratedNugetDir>.\nuget\</GeneratedNugetDir>
    <NuspecFile>$(GeneratedNugetDir)MyCodeShow.LogLib.nuspec</NuspecFile>
    <OutputPath>$(GeneratedNugetDir)</OutputPath>
    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.SourceLink.Common" Version="1.0.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" 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.

Create packageId.nuspec

<?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.0</version>
    <owners>Bhanu Marella</owners>
    <authors>Bhanu Marella</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.0</releaseNotes>
    <language>en-US</language>
    <iconUrl>https://github.com/mycodeshow-dev/my-code-show/blob/main/logo.png</iconUrl>
    <projectUrl>https://mycodeshow.dev/</projectUrl>
    <license type="expression">MIT</license>
    <tags>app insights, 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="..\Build\**" target="build\" />
    <file src="..\MyCodeShow.LogLib.targets" target="build\" />
    <file src="..\bin\Debug\net5.0\MyCodeShow.LogLib.dll" target="lib\net5.0\Logging.ApiInsights.dll" />
  </files>
</package>

The main thing 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.

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: 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

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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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 561 8/25/2021
1.0.6 480 8/15/2021
1.0.5 466 8/15/2021
1.0.4 497 8/15/2021
1.0.3 467 8/15/2021
1.0.2 478 8/15/2021
1.0.1 941 8/15/2021

MyCodeShow 1.0.1