@@ -14,6 +14,7 @@ namespace Elmah.Io.Functions
14
14
internal static class MessageShipper
15
15
{
16
16
private static readonly string _assemblyVersion = typeof ( MessageShipper ) . Assembly . GetName ( ) . Version . ToString ( ) ;
17
+ private static readonly string _elmahIoClientAssemblyVersion = typeof ( IElmahioAPI ) . Assembly . GetName ( ) . Version . ToString ( ) ;
17
18
#pragma warning disable CS0618 // Type or member is obsolete
18
19
private static readonly string _functionsAssemblyVersion = typeof ( FunctionExceptionContext ) . Assembly . GetName ( ) . Version . ToString ( ) ;
19
20
@@ -46,6 +47,67 @@ public static async Task Ship(FunctionExceptionContext exceptionContext, HttpCon
46
47
Application = options . Application ,
47
48
} ;
48
49
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
+ {
49
111
if ( elmahIoClient == null )
50
112
{
51
113
elmahIoClient = ElmahioAPI . Create ( options . ApiKey , new ElmahIoOptions
@@ -72,16 +134,6 @@ public static async Task Ship(FunctionExceptionContext exceptionContext, HttpCon
72
134
options . OnError ? . Invoke ( args . Message , args . Error ) ;
73
135
} ;
74
136
}
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
- }
85
137
}
86
138
87
139
/// <summary>
0 commit comments