logging - 如何在 F# Fable 中登录 Application Insights?

标签 logging f# azure-application-insights fable-f#

我正在开发一个SAFE F# 中的应用程序,其中一部分是将一些日志发送到 Azure 中的 Application Insights。服务器端日志记录有点easy :

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()

现在我想在《寓言》的客户端做类似的事情。我有一个 AI key ,我需要以某种方式将数据发送到 Azure。相同的代码不会转换为 JS。

最佳答案

这可以通过 dynamic programming 来实现《寓言》中。

  1. package.json中添加AI JS依赖:
{
    ...
    "devDependencies": {
        ...
        "applicationinsights-js": "^1.0.20"
    }
}
  • webpack.config.js 中反射(reflect)它:
  • fsharpEntry: {
        "app": [
             ...
            "applicationinsights-js"
        ]
    }
    
  • 设置日志记录(在应用的初始化阶段调用此方法):
  • open Fable.Core.JsInterop
    open Fable.Import.Browser
    
    let setup() = 
        let key = <key>
        let config = createObj [ "instrumentationKey" ==> key ]
        window?appInsights?downloadAndSetup config
    
  • 像这样记录:
  • let log message = window?appInsights?trackTrace message
    

    也许有更充分和/或类型安全的方法,但这可行。

    关于logging - 如何在 F# Fable 中登录 Application Insights?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56145536/

    相关文章:

    c# - 如何与 .net 中的另一个项目链接

    f# - TypeProvider 可以将资源添加到生成的程序集中吗?

    .net - 函数未被调用指定次数

    azure-application-insights - Azure Monitor 对已筛选的自定义指标发出警报,小于大小写

    azure-application-insights - 应用程序洞察中请求的持续时间范围

    logging - 是否可以将自定义日志文件添加到由Elastic beantalk的“eb logs”命令捕获的日志中?

    除了级别限制之外的 Java JUL 日志记录传播

    python - Django:登录manage.py会导致误导性异常和回溯

    c# - 仅将 IDbInterceptor 挂接到 EntityFramework DbContext 一次

    c# - 使用 C# 读取 AppInsights 的 JSON 输出