AlexaVoxCraft.Logging 1.0.1.54

dotnet add package AlexaVoxCraft.Logging --version 1.0.1.54
                    
NuGet\Install-Package AlexaVoxCraft.Logging -Version 1.0.1.54
                    
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="AlexaVoxCraft.Logging" Version="1.0.1.54" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AlexaVoxCraft.Logging" Version="1.0.1.54" />
                    
Directory.Packages.props
<PackageReference Include="AlexaVoxCraft.Logging" />
                    
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 AlexaVoxCraft.Logging --version 1.0.1.54
                    
#r "nuget: AlexaVoxCraft.Logging, 1.0.1.54"
                    
#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.
#addin nuget:?package=AlexaVoxCraft.Logging&version=1.0.1.54
                    
Install AlexaVoxCraft.Logging as a Cake Addin
#tool nuget:?package=AlexaVoxCraft.Logging&version=1.0.1.54
                    
Install AlexaVoxCraft.Logging as a Cake Tool

๐Ÿ”ฃ Alexa Vox Craft

Alexa Vox Craft is a modular, opinionated library for building Alexa skills in C# using .NET. It leverages System.Text.Json, MediatR patterns, and extensible components for building and maintaining robust Alexa skills with support for:

  • โœ… Clean separation of concerns using MediatR
  • โœ… JSON (de)serialization with full control via System.Text.Json
  • โœ… APL (Alexa Presentation Language) model support and utilities
  • โœ… Custom converters for object, enum, and polymorphic types
  • โœ… Lambda-ready with logging, tracing, and testability in mind

What does "AlexaVoxCraft" mean?

  • Alexa: Represents the integration with Amazon Alexa, the voice service powering devices like Amazon Echo.
  • VoxCraft: Signifies the focus on voice-driven interactions, leveraging the VoxCraft framework.

๐Ÿ“ฆ Credits:


๐ŸŽ๏ธ Packages

Package Build Status NuGet GitHub Downloads
AlexaVoxCraft.Model Build NuGet ๐Ÿ“ Source NuGet Downloads
AlexaVoxCraft.Model.Apl Build NuGet ๐Ÿ“ Source NuGet Downloads
AlexaVoxCraft.MediatR.Lambda Build NuGet ๐Ÿ“ Source NuGet Downloads
AlexaVoxCraft.MediatR Build NuGet ๐Ÿ“ Source NuGet Downloads
AlexaVoxCraft.Logging Build NuGet ๐Ÿ“ Source NuGet Downloads

๐Ÿš€ Getting Started

1. Install Required Packages

Install only the packages you need! If you're not using MediatR or APL features, you can omit those dependencies.

dotnet add package AlexaVoxCraft.Model
# Optional:
dotnet add package AlexaVoxCraft.MediatR.Lambda

2. Create a Lambda Entry Point

await LambdaHostExtensions.RunAlexaSkill<YourAlexaSkillFunction>();

3. Create Your Function Class

public sealed class YourAlexaSkillFunction : AlexaSkillFunction<SkillRequest, SkillResponse>
{
    protected override void Init(IHostBuilder builder)
    {
        builder
            .UseHandler<LambdaHandler, SkillRequest, SkillResponse>()
            .ConfigureServices((context, services) =>
            {
                services.AddSkillMediator(context.Configuration,
                    cfg => { cfg.RegisterServicesFromAssemblyContaining<Program>(); });
            });
    }
}

4. Handle Requests with MediatR

Handlers in AlexaVoxCraft are expected to implement IRequestHandler<T> and optionally implement ICanHandle to provide routing logic.

public sealed class LaunchRequestHandler : IRequestHandler<LaunchRequest>
{
    public bool CanHandle(IHandlerInput handlerInput) =>
        handlerInput.RequestEnvelope.Request is LaunchRequest;

    public async Task<SkillResponse> Handle(IHandlerInput input, CancellationToken cancellationToken = default)
    {
        return await input.ResponseBuilder.Speak("Hello world!").WithShouldEndSession(true)
            .GetResponse(cancellationToken);
    }
}

๐Ÿ“‹ Logging & Diagnostics

AlexaVoxCraft uses Serilog for structured logging by default. You can configure logging output by adding the following to your appsettings.json:

"Serilog": {
  "Using": [ "Serilog.Sinks.Console" ],
  "WriteTo": [
    {
      "Name": "Console",
      "Args": {
      "formatter": "AlexaVoxCraft.Logging.Serialization.AlexaCompactJsonFormatter, AlexaVoxCraft.Logging"
      }
    }
  ],
  "MinimumLevel": {
    "Default": "Information",
    "Override": {
      "Microsoft": "Warning",
      "Microsoft.AspNetCore": "Warning"
    }
  }
}

โ„น๏ธ Debugging Tip: To enable logging of raw Alexa skill requests and responses during development, add the following line under Override. This is not recommended for production environments.

"AlexaVoxCraft.MediatR.Lambda.Serialization": "Debug"

๐Ÿงพ Formatter Attribution

๐Ÿ”ง The AlexaCompactJsonFormatter included in this library is adapted from Serilog.Formatting.Compact.CompactJsonFormatter.
This customized formatter renames reserved field names (e.g., @t, @l, @m) to AWS-safe equivalents (_t, _l, _m) to improve compatibility with CloudWatch Logs and metric filters.

Original work ยฉ Serilog Contributors, licensed under the MIT License.


๐Ÿงช Unit Testing

Sample projects show how to load Alexa requests from JSON and assert deserialized structure. Tests include validation of:

  • Correct parsing of SkillRequest types
  • APL component deserialization
  • Proper usage of custom converters

๐Ÿ›  Utilities and Helpers

  • EnumHelper: Convert to/from [EnumMember]-decorated enums
  • ObjectConverter: Deserialize polymorphic object values
  • BasePolymorphicConverter<T>: Handle APL and directive subtypes
  • AlexaLambdaSerializer: Custom ILambdaSerializer with logging support

โš ๏ธ Error Handling

To intercept and respond to exceptions in your MediatR pipeline, implement the IExceptionHandler interface:

public sealed class MyExceptionHandler : IExceptionHandler
{
    public Task<bool> CanHandle(IHandlerInput handlerInput, Exception ex, CancellationToken cancellationToken = default)
    {
        return Task.FromResult(true); // Catch all
    }

    public Task<SkillResponse> Handle(IHandlerInput handlerInput, Exception ex, CancellationToken cancellationToken = default)
    {
        var response = handlerInput.ResponseBuilder.Speak("Something went wrong. Please try again.");
        return response.GetResponse(cancellationToken);
    }
}

No manual registration is required. Exception handlers are picked up automatically via AddSkillMediator(...).


๐Ÿ› Sample Projects

Sample Project Description
Sample.Skill.Function A minimal Alexa skill using this library
Sample.Apl.Function A sample APL skill to demonstrate working with APL

Each sample demonstrates MediatR integration, serialization support, custom directives, and Lambda bootstrapping.


๐Ÿคญ Roadmap

  • โœ… Full widget lifecycle support
  • โœ… Advanced directive handling
  • โš–๏ธ OpenTelemetry & logging enrichment
  • ๐Ÿ”„ Documentation site

๐Ÿค Contributing

PRs are welcome! Please submit issues and ideas to help make this toolkit even better.


Contributors โœจ

Thanks goes to these wonderful people (emoji key):

<table> <tbody> <tr> <td align="center" valign="top" width="14.28%"><a href="https://github.com/LayeredCraft"><img src="https://avatars.githubusercontent.com/u/1405469?v=4?s=100" width="100px;" alt="Nick Cipollina"/><br /><sub><b>Nick Cipollina</b></sub></a><br /><a href="#content-LayeredCraft" title="Content">๐Ÿ”“</a></td> </tr> </tbody> </table>

This project follows the all-contributors specification. Contributions of any kind welcome!


๐Ÿ“œ License

MIT

This project is licensed under the MIT License. See the LICENSE file for details.

Stargazers over time

Stargazers over time

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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 is compatible.  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 (1)

Showing the top 1 NuGet packages that depend on AlexaVoxCraft.Logging:

Package Downloads
AlexaVoxCraft.MediatR.Lambda

Lambda hosting and middleware integration for Alexa skills using MediatR and AlexaVoxCraft.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1.54 158 5/21/2025
1.0.1.53 155 5/19/2025
1.0.1.50 254 5/13/2025
1.0.1.49 222 5/13/2025
1.0.1-beta.52 106 5/19/2025
1.0.1-beta.48 197 5/13/2025
1.0.1-beta.47 194 5/13/2025
1.0.1-beta.46 192 5/13/2025
1.0.1-beta.45 195 5/13/2025