@@ -14,6 +14,7 @@ namespace Elmah.Io.Functions
1414 internal static class MessageShipper
1515 {
1616 private static readonly string _assemblyVersion = typeof ( MessageShipper ) . Assembly . GetName ( ) . Version . ToString ( ) ;
17+ private static readonly string _elmahIoClientAssemblyVersion = typeof ( IElmahioAPI ) . Assembly . GetName ( ) . Version . ToString ( ) ;
1718#pragma warning disable CS0618 // Type or member is obsolete
1819 private static readonly string _functionsAssemblyVersion = typeof ( FunctionExceptionContext ) . Assembly . GetName ( ) . Version . ToString ( ) ;
1920
@@ -46,6 +47,67 @@ public static async Task Ship(FunctionExceptionContext exceptionContext, HttpCon
4647 Application = options . Application ,
4748 } ;
4849
50+ EnsureClient ( options ) ;
51+
52+ try
53+ {
54+ await elmahIoClient . Messages . CreateAndNotifyAsync ( options . LogId , createMessage , cancellationToken ) ;
55+ }
56+ catch ( Exception e )
57+ {
58+ options . OnError ? . Invoke ( createMessage , e ) ;
59+ // If there's a Exception while generating the error page, re-throw the original exception.
60+ }
61+ }
62+
63+ public static void CreateInstallation ( ElmahIoFunctionOptions options )
64+ {
65+ try
66+ {
67+ var logger = new LoggerInfo
68+ {
69+ Type = "Elmah.Io.Functions" ,
70+ Assemblies =
71+ [
72+ new AssemblyInfo
73+ {
74+ Name = "Elmah.Io.Functions" ,
75+ Version = _assemblyVersion ,
76+ } ,
77+ new AssemblyInfo
78+ {
79+ Name = "Elmah.Io.Client" ,
80+ Version = _elmahIoClientAssemblyVersion ,
81+ } ,
82+ new AssemblyInfo
83+ {
84+ Name = "Microsoft.Azure.WebJobs.Host" ,
85+ Version = _functionsAssemblyVersion ,
86+ }
87+ ] ,
88+ ConfigFiles = [ ] ,
89+ Properties = [ ] ,
90+ } ;
91+
92+ var installation = new CreateInstallation
93+ {
94+ Name = options . Application ,
95+ Type = "azurefunction" ,
96+ Loggers = [ logger ]
97+ } ;
98+
99+ EnsureClient ( options ) ;
100+
101+ elmahIoClient . Installations . Create ( options . LogId . ToString ( ) , installation ) ;
102+ }
103+ catch
104+ {
105+ // We don't want to crash the entire application if the installation fails. Carry on.
106+ }
107+ }
108+
109+ private static void EnsureClient ( ElmahIoFunctionOptions options )
110+ {
49111 if ( elmahIoClient == null )
50112 {
51113 elmahIoClient = ElmahioAPI . Create ( options . ApiKey , new ElmahIoOptions
@@ -72,16 +134,6 @@ public static async Task Ship(FunctionExceptionContext exceptionContext, HttpCon
72134 options . OnError ? . Invoke ( args . Message , args . Error ) ;
73135 } ;
74136 }
75-
76- try
77- {
78- await elmahIoClient . Messages . CreateAndNotifyAsync ( options . LogId , createMessage , cancellationToken ) ;
79- }
80- catch ( Exception e )
81- {
82- options . OnError ? . Invoke ( createMessage , e ) ;
83- // If there's a Exception while generating the error page, re-throw the original exception.
84- }
85137 }
86138
87139 /// <summary>
0 commit comments