Skip to content

Instantly share code, notes, and snippets.

View jiimaho's full-sized avatar
🎯
Focusing

Jim Aho jiimaho

🎯
Focusing
View GitHub Profile
@jiimaho
jiimaho / Models.cs
Last active August 14, 2021 09:06
Models
public class CustomerIntegrationModel
{
public string CustomerId { get; set; }
public string Name { get; set; }
}
public class CustomerRequestModel
{
public string CustomerId { get; set; }
public string Name { get; set; }
@jiimaho
jiimaho / Exception.cs
Created June 21, 2021 19:17
Good usage of fatal logging
try
{
// notify customer about rejected card purchase
}
catch(Exception e)
{
_logger.Fatal(e, "Failed to notify customer about rejected card purchase. Please ask Customer Care Center to call the customer and tell him/her about this to avoid degradation of reputation");
}
@jiimaho
jiimaho / Exception.cs
Created June 21, 2021 19:14
Better logging in catch
try
{
// network call
}
catch(Exception e)
{
_logger.Warning(e, "Network call failed");
}
@jiimaho
jiimaho / Exception.cs
Created June 21, 2021 18:55
Bad logging of errror
try
{
// network call
}
catch(Exception e)
{
_logger.Error(e, "Network call failed");
}
public class Function
{
private static ServiceProvider ServiceProvider { get; set; }
/// <summary>
/// The parameterless constructor is what Lambda uses to construct your instance the first time.
/// It will only ever be called once for the lifetime of the container that it's running on.
/// We want to build our ServiceProvider once, and then use the same provider in all subsequent
/// Lambda invocations. This makes things like using local MemoryCache techniques viable (Just
/// remember that you can never count on a locally cached item to be there!)
@jiimaho
jiimaho / gist:5f2ed26af284975f64ab46070a1e5ab9
Created December 21, 2020 11:56
.NET Core TimeZoneInfo.GetSystemTimeZones() id's
Pacific/Niue
Pacific/Midway
Pacific/Pago_Pago
America/Adak
Pacific/Rarotonga
Pacific/Tahiti
Pacific/Honolulu
Pacific/Marquesas
America/Metlakatla
America/Sitka
@jiimaho
jiimaho / Startup.cs
Created May 31, 2020 18:28
Application Insights DI custom telemetry processor
public void ConfigureServices(IServiceCollection services)
{
// ....
services.AddApplicationInsightsTelemetry(Configuration);
services.AddApplicationInsightsTelemetryProcessor<IgnoreRequestPathsTelemetryProcessor>();
// ....
}
public class IgnoreRequestPathsTelemetryProcessor : ITelemetryProcessor
{
private readonly ITelemetryProcessor _next;
public IgnoreRequestPathsTelemetryProcessor(ITelemetryProcessor next)
{
_next = next;
}
public void Process(ITelemetry item)
@jiimaho
jiimaho / Makefile
Last active May 3, 2020 18:09
Publish nuget to local feed with Make
# Builds all nugets for easier local development
mac:
dotnet pack src/Your.Project.Here.csproj -o ~/localfeed
windows:
dotnet pack src/Your.Project.Here.csproj -o c:\localfeed
@jiimaho
jiimaho / AnotherWorker.cs
Created April 8, 2020 06:12
BackgroundService and cancellation tokens
public class AnotherWorker : BackgroundService
{
private readonly IHostApplicationLifetime _hostApplicationLifetime;
public AnotherWorker(IHostApplicationLifetime hostApplicationLifetime)
{
_hostApplicationLifetime = hostApplicationLifetime;
}
public override Task StartAsync(CancellationToken cancellationToken)