c#metro ETW-未记录某些事件

c#metro ETW-未记录某些事件,c#,logging,etw,C#,Logging,Etw,我有一个C#/XAML应用程序,我使用ETW将事件记录到平面文件中 9/10次未设置StorageFile且未记录我的事件 建造商: public AppEventSource(string logFileName) { this._logFileName = logFileName; AssignLocalFile(); } private async void AssignLocalFile() { _storageFile = await ApplicationD

我有一个C#/XAML应用程序,我使用ETW将事件记录到平面文件中

9/10次未设置StorageFile且未记录我的事件

建造商:

public AppEventSource(string logFileName)
{
    this._logFileName = logFileName;
    AssignLocalFile();
}

private async void AssignLocalFile()
{
    _storageFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(
        _logFileName), 
        CreationCollisonOption.OpenIfExists);
}

private async void WriteToFile(IEnumerable<string> lines)
{
    await _semaphore.WaitAsync();

    await Task.Run(async() =>
    {
        await FileIO.AppendLinesAsync(_storageFile, lines);
        _semaphore.Release();
    });
}

protected override void OnEventWritten(EventWrittenEventArgs eventData)
{
    if(_storageFile == null) return;
    List<string> lines = new List<string>();
    // formatting stuff....
    WriteToFile(lines);
}
和示例日志:

AppEventsSource.Log.Info("log entry #1");

您应该避免
async void
(改用
async Task
)。您是否收到任何异常?没有异常,仅当我逐步执行代码时,AssignLocalFile始终返回null,但日志文件已创建。
AppEventsSource.Log.Info("log entry #1");