Skip to content
This repository has been archived by the owner on Feb 17, 2024. It is now read-only.

A library for generating EventSource classes from interfaces at run-time

License

Notifications You must be signed in to change notification settings

aelij/EventSourceExtensions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

EventSourceExtensions

A .NET Standard (1.1) library for generating EventSource classes from interfaces at run-time

  • Mapping custom parameter types to one or more other parameters
  • Adding parameters
  • Fallback converter

NuGet

Install-Package EventSourceExtensions

Usage

class Foo
{
   public int A { get ;}
   public Bar B { get; }
}

var configuration = EventSourceConfiguration.Empty
                        .WithMapping<Foo>(m => m.Map(foo => foo.A, "a").Map(foo => foo.B, "b"))
                        .WithAdditionalParameter(() => Trace.CorrelationManager.ActivityId, "correlationId"));
                        
var generator = new EventSourceGenerator(configuration,
                        fallbackConverter: o => JsonConvert.SerializeObject(o));

[EventSourceInterface(Name = "MyEventSource")]
interface IMyEventSource
{
   [Event(1)]
   void Log(Foo foo);
}

var fooSource = generator.Get<IMyEventSource>(); // optionally overrride global configuration here

fooSource.Log(new Foo());

The actual EventSource implementation would have this signature:

[Event(1)]
void Log(int a, string b, Guid correlationId);

b is a string since no converter was specified for type Bar, and it's not a natively supported EventSource type. So it would require specifying a fallbackConverter, which always returns a string. In this example, it would attempt to convert Bar to JSON.

Building

Open EventSourceExtensions.sln in Visual Studio 2017

About

A library for generating EventSource classes from interfaces at run-time

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages