更新 0603:
我的 app.config:
使用 Visual Studio 进行调试:
更新:请按照下面的屏幕截图,并尝试找到您发送的信息。如果您仍然找不到信息,请提供详细代码(删除个人/重要数据,如检测密钥,并提供您正在使用的 nuget 包和版本)。
1.点击概览页面中的搜索按钮:
2.在搜索画面中,正确设置Local time和Event类型,然后尝试搜索消息:
您最好提供设置 log4net 和应用洞察密钥的代码。
我用 wpf 项目做了一个简单的测试,下面的代码工作正常:
public partial class MainWindow : Window
{
private static readonly ILog log = LogManager.GetLogger(typeof(MainWindow));
public MainWindow()
{
TelemetryConfiguration.Active.InstrumentationKey = "the key";
log4net.Config.XmlConfigurator.Configure();
log.Info("wpf aaaa11111");
InitializeComponent();
}
}
您收到错误“AI:服务器遥测通道未初始化”,可能是由于一些不正确的配置,例如在上面的工作代码中使用以下代码:
//when add the code, it will cause the error you mentioned.
TelemetryConfiguration.Active.TelemetryChannel = new ServerTelemetryChannel();
如果您必须添加遥测客户端(带配置),并且配置正确,log4net 和遥测客户端都可以将数据发送到应用程序洞察。如下代码:
public partial class MainWindow : Window
{
private readonly TelemetryClient telemetryClient;
private static readonly ILog log = LogManager.GetLogger(typeof(MainWindow));
public MainWindow()
{
//configure the key here for log4net
TelemetryConfiguration.Active.InstrumentationKey = "the key";
log4net.Config.XmlConfigurator.Configure();
var config = new TelemetryConfiguration();
//configure the key here for telemetry client
config.InstrumentationKey = "the key";
telemetryClient = new TelemetryClient(config);
log.Info("wpf aaaa333");
log.Info(TelemetryConfiguration.Active.TelemetryChannel.ToString());
telemetryClient.TrackTrace("it is going to start!");
InitializeComponent();
}
}