如何使用希伯来语保存TraceListner以Csv文件写入日志 [英] How to save TraceListner Write Log In Csv File In Hebrew Language

查看:108
本文介绍了如何使用希伯来语保存TraceListner以Csv文件写入日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用TextWriterTraceListener登录我的WPF应用程序。该文件以csv格式存储。我用希伯来语写文字。问题是,当我在MS Excel中打开该csv文件时,它将打开,如下图所示,这是不正确的。但是当我使用记事本再次将文件保存为UTF8格式时。它开得很好。我认为tracelistner没有以UTF8格式保存csv文件。我该如何解决这个问题?



Excel表格快照链接:http://ge.tt/7CLTAGh1/v/0?c



App.config代码

I am logging in my WPF application using TextWriterTraceListener. The file is stored in csv format. I am writing text in hebrew language. The problem is that when I open that csv file in MS Excel it open as shown in picture below which is not correct. But when i save the file again as UTF8 format using a Notepad. It opens perfectly fine. I think tracelistner is not saving csv file in UTF8 format. How should i fix this?

Excelsheet snapshot link: http://ge.tt/7CLTAGh1/v/0?c

App.config code

<system.diagnostics>
    <trace autoflush="true" indentsize="3">
      <listeners>
        <add name="myListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="C:\POSH\AnnaAssetData\ANNALog2.csv" />
        <remove name="Default" />
      </listeners>
    </trace>
  </system.diagnostics>







C#代码:






C# code:

var line   = string.Format("{0},{1},{2},{3}",DateTime.Now, Thread.CurrentThread.CurrentUICulture, view,extraData);
Trace.WriteLine(line);





Logger App.config





Logger App.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
  </configSections>
  <loggingConfiguration name="" tracingEnabled="true" defaultCategory="Audit">
    <listeners>
      <add name="Event Log Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
          listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
          source="Enterprise Library Logging" formatter="Text Formatter"
          log="" machineName="." traceOutputOptions="None" />
      <add name="Rolling Flat File Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
          listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
          fileName="Audit.log" rollInterval="Day" />
    </listeners>
    <formatters>
      <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
          template="Timestamp: {timestamp}{newline}Message: {message}{newline}Category: {category}{newline}Priority: {priority}{newline}Severity: {severity}{newline}Title:{title}{newline}Extended Properties: {dictionary({key} - {value}{newline})}"
          name="Text Formatter" />
    </formatters>
    <categorySources>
      <add switchValue="All" name="Audit">
        <listeners>
          <add name="Rolling Flat File Trace Listener" />
        </listeners>
      </add>
      <add switchValue="Error" name="Exception">
        <listeners>
          <add name="Event Log Listener" />
          <add name="Rolling Flat File Trace Listener" />
        </listeners>
      </add>
    </categorySources>
    <specialSources>
      <allEvents switchValue="All" name="All Events" />
      <notProcessed switchValue="All" name="Unprocessed Category" />
      <errors switchValue="All" name="Logging Errors & Warnings">
        <listeners>
          <add name="Rolling Flat File Trace Listener" />
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>
</configuration>

推荐答案

这篇关于如何使用希伯来语保存TraceListner以Csv文件写入日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆