MyCodeShow.LogLib
1.0.1
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
<PackageReference Include="MyCodeShow.LogLib" Version="1.0.1" />
paket add MyCodeShow.LogLib --version 1.0.1
#r "nuget: MyCodeShow.LogLib, 1.0.1"
// Install MyCodeShow.LogLib as a Cake Addin
#addin nuget:?package=MyCodeShow.LogLib&version=1.0.1
// Install MyCodeShow.LogLib as a Cake Tool
#tool nuget:?package=MyCodeShow.LogLib&version=1.0.1
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 | Versions 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. |
-
- MediatR (>= 9.0.0)
- Microsoft.ApplicationInsights (>= 2.18.0)
- Microsoft.ApplicationInsights.NLogTarget (>= 2.18.0)
- Newtonsoft.Json (>= 13.0.1)
- NLog (>= 4.7.10)
- NLog.Extensions.Logging (>= 1.7.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
MyCodeShow 1.0.1