Permalink
Browse files

Introduced EventTracingProvider

  • Loading branch information...
mbrenn committed Jan 6, 2019
1 parent a66c4fb commit ea8d6cd387259d2a8d2c56495b3cbbe1fdf35b3b
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
</startup>
</configuration>
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{9CCAA7EA-EB42-48B2-8946-BFD5992445CE}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>BurnSystems.Logging.Console.DotNetFW</RootNamespace>
<AssemblyName>BurnSystems.Logging.Console.DotNetFW</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="WorkingMan.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BurnSystems\BurnSystems.csproj">
<Project>{5B491372-1DAE-4B30-991D-CD82BC83A0A5}</Project>
<Name>BurnSystems</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
@@ -0,0 +1,31 @@
using System.Threading;
using BurnSystems.Logging.Provider;

namespace BurnSystems.Logging.Console.DotNetFW
{
class Program
{
static void Main(string[] args)
{
TheLog.AddProvider(new ConsoleProvider(), LogLevel.Trace);
TheLog.AddProvider(new FileProvider("test.log", true), LogLevel.Info);
TheLog.AddProvider(new EventTracingProvider(), LogLevel.Trace);
TheLog.Trace("Not added");
Thread.Sleep(100);
TheLog.Debug("This is a debug message");
Thread.Sleep(80);
TheLog.Info("We have an info message.");
Thread.Sleep(80);
TheLog.Warn("We have a warn");
Thread.Sleep(80);
TheLog.Error("Error Occured....");
Thread.Sleep(80);
TheLog.Fatal("We have to quit the application due to loss of O².");
Thread.Sleep(80);
new WorkingMan().Work();

System.Console.WriteLine("Press key");
//System.Console.ReadKey();
}
}
}
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// Allgemeine Informationen über eine Assembly werden über die folgenden
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
// die einer Assembly zugeordnet sind.
[assembly: AssemblyTitle("BurnSystems.Logging.Console.DotNetFW")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BurnSystems.Logging.Console.DotNetFW")]
[assembly: AssemblyCopyright("Copyright © 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly
// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von
// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen.
[assembly: ComVisible(false)]

// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
[assembly: Guid("9ccaa7ea-eb42-48b2-8946-bfd5992445ce")]

// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
//
// Hauptversion
// Nebenversion
// Buildnummer
// Revision
//
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,12 @@
namespace BurnSystems.Logging.Console.DotNetFW
{
public class WorkingMan
{
private ILogger logger = new ClassLogger(typeof(WorkingMan));

public void Work()
{
logger.Info("We are working.");
}
}
}
@@ -1,4 +1,5 @@
using System.Threading;
using System.Diagnostics;
using System.Threading;
using BurnSystems.Logging.Provider;

namespace BurnSystems.Logging.Console
@@ -9,6 +10,7 @@ static void Main(string[] args)
{
TheLog.AddProvider(new ConsoleProvider(), LogLevel.Trace);
TheLog.AddProvider(new FileProvider("test.log", true), LogLevel.Info);
TheLog.AddProvider(new EventTracingProvider(), LogLevel.Trace);
TheLog.Trace("Not added");
Thread.Sleep(100);
TheLog.Debug("This is a debug message");
@@ -25,7 +27,6 @@ static void Main(string[] args)

System.Console.WriteLine("Press key");
System.Console.ReadKey();

}
}
}
@@ -3,13 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28010.2050
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BurnSystems", "BurnSystems\BurnSystems.csproj", "{5B491372-1DAE-4B30-991D-CD82BC83A0A5}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BurnSystems", "BurnSystems\BurnSystems.csproj", "{5B491372-1DAE-4B30-991D-CD82BC83A0A5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BurnSystems.Logging.Console", "BurnSystems.Logging.Console\BurnSystems.Logging.Console.csproj", "{4D00FFD9-DA4A-4948-AE13-86C06A924D14}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BurnSystems.Logging.Tests", "BurnSystems.Logging.Tests\BurnSystems.Logging.Tests.csproj", "{95718A3D-8243-4A94-909C-724574D084B6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BurnSystems.Tests", "BurnSystems.Tests\BurnSystems.Tests.csproj", "{D1AAD0EA-4297-4323-BA84-4ECD8FB79D13}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BurnSystems.Tests", "BurnSystems.Tests\BurnSystems.Tests.csproj", "{D1AAD0EA-4297-4323-BA84-4ECD8FB79D13}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BurnSystems.Logging.Console.DotNetFW", "BurnSystems.Logging.Console.DotNetFW\BurnSystems.Logging.Console.DotNetFW.csproj", "{9CCAA7EA-EB42-48B2-8946-BFD5992445CE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -51,6 +53,14 @@ Global
{D1AAD0EA-4297-4323-BA84-4ECD8FB79D13}.Release|Any CPU.Build.0 = Release|Any CPU
{D1AAD0EA-4297-4323-BA84-4ECD8FB79D13}.Release|x86.ActiveCfg = Release|Any CPU
{D1AAD0EA-4297-4323-BA84-4ECD8FB79D13}.Release|x86.Build.0 = Release|Any CPU
{9CCAA7EA-EB42-48B2-8946-BFD5992445CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9CCAA7EA-EB42-48B2-8946-BFD5992445CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9CCAA7EA-EB42-48B2-8946-BFD5992445CE}.Debug|x86.ActiveCfg = Debug|Any CPU
{9CCAA7EA-EB42-48B2-8946-BFD5992445CE}.Debug|x86.Build.0 = Debug|Any CPU
{9CCAA7EA-EB42-48B2-8946-BFD5992445CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9CCAA7EA-EB42-48B2-8946-BFD5992445CE}.Release|Any CPU.Build.0 = Release|Any CPU
{9CCAA7EA-EB42-48B2-8946-BFD5992445CE}.Release|x86.ActiveCfg = Release|Any CPU
{9CCAA7EA-EB42-48B2-8946-BFD5992445CE}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Tracing;

namespace BurnSystems.Logging.Provider
{
[EventSource(Name="BurnSystems")]
public class EventTracingProvider : EventSource, ILogProvider
{
/// <summary>
/// Stores the categories of the event
/// </summary>
private Dictionary<string, int> _categories = new Dictionary<string, int>();

[NonEvent]
public void LogMessage(LogMessage logMessage)
{
int eventId;
lock(_categories)
{
if (string.IsNullOrEmpty(logMessage.Category))
{
eventId = 1;
}
else
{
if (!_categories.TryGetValue(logMessage.Category, out eventId))
{
eventId = Math.Min(65535, _categories.Count + 2);
_categories[logMessage.Category] = eventId;
}
}
}

InternalLog(eventId, logMessage.Category ?? string.Empty, logMessage.ToString());
}

[Event(1, Message = "{0}, {1}:{2}", Level = EventLevel.Informational)]
public void InternalLog(int eventId, string category, string message)
{
if (IsEnabled())
{
WriteEvent(1, eventId, category, message);
}
}


}
}

0 comments on commit ea8d6cd

Please sign in to comment.