FlashLog 1.0.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package FlashLog --version 1.0.3                
NuGet\Install-Package FlashLog -Version 1.0.3                
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="FlashLog" Version="1.0.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FlashLog --version 1.0.3                
#r "nuget: FlashLog, 1.0.3"                
#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 FlashLog as a Cake Addin
#addin nuget:?package=FlashLog&version=1.0.3

// Install FlashLog as a Cake Tool
#tool nuget:?package=FlashLog&version=1.0.3                

Instructions

Follow these steps to add FlashLog© to your project

  1. Install nuget postsharp 6.10.5 (in first run only you should create your postsharp license)
  2. Create a file "nlog.config" in your project root, change it's "Copy to output directory" to "Copy if newer", and copy this content:
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

  <extensions>
    <add assembly="Microsoft.ApplicationInsights.NLogTarget" />
  </extensions>

  <targets>
    <target
          xsi:type="Console"
          name="consoleTarget"
          layout="${longdate} | ${level:uppercase=false} | ${logger} | ${message}">
    </target>
    <target
          xsi:type="ApplicationInsightsTarget"
          name="aiTarget"
          instrumentationKey="[instrumentationKey]">
      <contextproperty name="threadid" layout="${threadid}" />
    </target>
    <target
          xsi:type="File"
          name="fileTarget"
          fileName="c:\logs\log.log"
          layout="${longdate} | ${level:uppercase=false} | ${logger} | ${message}" />
    <target
          name="Mail"
          xsi:type="Mail"
          html="true"
          subject="AspectLogger Trace"
          body="${longdate} | ${level:uppercase=false} | ${logger} | ${message}"
          to="[To_mail]"
          from="[From_mail]"
          Encoding="UTF-8"
          smtpUsername="[From_mail]"
          enableSsl="True"
          smtpPassword="[Password]"
          smtpAuthentication="Basic"
          smtpServer="[smtp_server]"
          smtpPort="[smtp_port]" />
  </targets>

  <rules>
    <logger name="*" minlevel="Trace" writeTo="consoleTarget,aiTarget,fileTarget" />
    <logger name="*" minlevel="Error" writeTo="consoleTarget,aiTarget,fileTarget,Mail" />
  </rules>
</nlog>

remember! this is your output settings: writeTo="consoleTarget,aiTarget,fileTarget"

consoleTarget = console window output aiTarget = application insights fileTarget = file in c:\logs\log.log

in case of exception a mail log too

  1. Change all the details according to yours
  2. create a file "app.config" in your executable, change it's "Copy to output directory" to "Copy if newer", and copy this content:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="logExceptionsOnly" value="false"/>
  </appSettings>
</configuration>

keep in mind that:

   <add key="logExceptionsOnly" value="true"/> //will print exceptions only
   <add key="logExceptionsOnly" value="false"/> //will print EVERY function entry + exceptions
  1. We are all set! now all you need to do is add an attribute [AspectLogger] in your class

Example for class with AspectLogger


class Program
{
    static void Main(string[] args)
    {
        MyClass testClass = new ();

        testClass.Func1();
        testClass.Func2();
    }
}


// this is the logger attribute that will log every step and exception of your class
[AspectLogger]
public class MyClass
{
	public void Func1()
	{}

	public void Func2()
	{}
}


the output will be:

2022-01-02 09:02:49.4440 | Info | FlashLog.Logging.NLogLogger | Entering Method:".ctor" 
2022-01-03 09:02:49.4441 | Info | FlashLog.Logging.NLogLogger | Entering Method:"Func1" 
2022-01-03 09:02:49.4442 | Info | FlashLog.Logging.NLogLogger | Entering Method:"Func2" 

Manual Print

FlashLog can also print log manually, add this code wherever you need to log.

Logger.GetLogger().Log("Print1");

the output will be:

2022-01-03 09:02:49.4580 | Info | FlashLog.Logging.NLogLogger | Print1 
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.5 609 11/1/2023
1.0.4 1,087 1/3/2022
1.0.3 717 1/3/2022
1.0.2 756 1/3/2022
1.0.1 720 1/1/2022
1.0.0 767 1/1/2022