【问题标题】:EventSource is not writing to SQL databaseEventSource 未写入 SQL 数据库
【发布时间】:2016-04-25 12:44:11
【问题描述】:

我正在使用 EventSource 通过 EnterpriseLibrary.SemanticLogging 将我的事件记录到 SQL 数据库中,

以下是测试方法:

    [TestMethod]
    public void Log_Test()
    {
        var eventListener = new ObservableEventListener();

        var sqlListener = SqlDatabaseLog.CreateListener("Instance", CloudConfigurationManager.GetSetting("ConnectionStringTrace"), "Traces");
        eventListener.EnableEvents(ApplicationEventSource.Log, EventLevel.LogAlways, Keywords.All);

        ApplicationEventSource.Log.ComponentNotLoaded("Milind", "Cheeta", "Core");

ApplicationEventSource 类通过以下方法从 EventSource 派生

        [Event(2,
        Keywords = Keywords.Component,
        Message = "Component: {2} not successfully loaded for user: {0} on machine: {1}",
        Task = Tasks.Load,
        Opcode = EventOpcode.Start,
        Level = EventLevel.Error)]
    public void ComponentNotLoaded(string userName, string machineName, string componentName)
    {
        WriteEvent(2, userName, machineName, componentName);
    }

我在 WriteEvent 时没有收到错误,但没有任何内容记录到表 Trace

【问题讨论】:

    标签: c# logging azure-sql-database eventsource


    【解决方案1】:

    请发布完整的 ApplicationEventSource 类。

    如果你像这样改变方法:

    public void ComponentNotLoaded(string userName, string machineName, string componentName)
    {
        if(IsEnabled())
            WriteEvent(2, userName, machineName, componentName);
    }
    

    会调用 WriteEvent 吗?如果不是,则结构中有问题。尝试使用 Event Source Analyzer 验证 EventSource 类。

    https://msdn.microsoft.com/en-us/library/dn774985(v=pandp.20).aspx#_Checking_an_event

    另外,设置数据库接收器的正常过程是这样的:

    eventListener.LogToSqlDatabase(
                    Environment.MachineName,
                    sqlConnectionString,
                );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-16
      • 1970-01-01
      • 2011-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多