psf*_*aki 4 logging f# azure-application-insights fable-f#
我正在用 F#开发一个SAFE应用程序,其中一部分是将一些日志发送到 Azure 中的 Application Insights。服务器端日志记录有点简单:
open Microsoft.ApplicationInsights
open Microsoft.ApplicationInsights.Extensibility
let getTelemetryClient() =
let key = <key>
TelemetryConfiguration.Active.InstrumentationKey <- key
TelemetryClient()
let log (message : string) =
let logger = (lazy getTelemetryClient()).Value
logger.TrackTrace message
logger.Flush()
Run Code Online (Sandbox Code Playgroud)
现在我想在客户端做一些类似的事情,在寓言中。我有一个 AI 密钥,我需要将数据发送到 Azure。相同的代码不会转换为 JS。
这可以通过寓言中的动态编程来实现。
package.json:{
...
"devDependencies": {
...
"applicationinsights-js": "^1.0.20"
}
}
Run Code Online (Sandbox Code Playgroud)
webpack.config.js:fsharpEntry: {
"app": [
...
"applicationinsights-js"
]
}
Run Code Online (Sandbox Code Playgroud)
open Fable.Core.JsInterop
open Fable.Import.Browser
let setup() =
let key = <key>
let config = createObj [ "instrumentationKey" ==> key ]
window?appInsights?downloadAndSetup config
Run Code Online (Sandbox Code Playgroud)
let log message = window?appInsights?trackTrace message
Run Code Online (Sandbox Code Playgroud)
也许有更合适和/或类型安全的方法,但这是有效的。
| 归档时间: |
|
| 查看次数: |
245 次 |
| 最近记录: |