log4net消息文本问题

发布于 2024-10-08 08:31:18 字数 4968 浏览 2 评论 0原文

我正在尝试使用 File Appender 使 log4net 工作。

我对消息使用指定的模式布局,但问题是我的日志文件中没有任何文本。仅有的 '??'符号

消息文本似乎在写入文件之前以某种方式被损坏。

我在 Windows Server 2008 上使用 Visual Studio 2008。log4net 在 global.asax 中初始化,

这是我的 log4net 配置。

<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"></section>
. . .
<log4net debug="true">
    <appender name="INFOFileAppender" type="log4net.Appender.FileAppender">
        <lockingmodel type="log4net.Appender.FileAppender+MinimalLock"/>
      <threshold value="INFO" />  
      <file value="AOKlogs.txt" />
        <appendtofile value="true" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
      </layout>          
    </appender>
    <root>
        <level value="ALLL" />
        <appender-ref ref="INFOFileAppender" />
    </root>
  </log4net>

我尝试过滚动文件和简单文件附加程序,但没有成功。

更新 我启用了调试并配置了 log4net 将调试日志写入 txt 文件。其内容如下:

我启用了调试日志到 txt 文件,其内容如下:

log4net:log4net 程序集 [log4net,版本 = 1.2.10.0,文化 = 中性,PublicKeyToken = 1b44e1d426115821]。从[C:\ Users \ ScarryComp \ AppData \ Local \ Temp \ Temporary ASP.NET Files \ website1 \ 7e2bf4c4 \ 4d1a1e05 \ assembly \ dl3 \ c6bded9b \ 0086655c_d353c601 \ log4net.DLL]加载。 (Microsoft Windows NT 6.1.7600.0 上的 .NET 运行时 [2.0.50727.4952]) log4net:DefaultRepositorySelector:defaultRepositoryType [log4net.Repository.Hierarchy.Hierarchy] log4net:DefaultRepositorySelector:为程序集创建存储库 [App_Code.ch9yol_l,Version=0.0.0.0,Culture=neutral,PublicKeyToken=null] log4net:DefaultRepositorySelector:程序集[App_Code.ch9yol_l,版本= 0.0.0.0,文化=中性,PublicKeyToken = null]从[C:\ Users \ ScarryComp \ AppData \ Local \ Temp \ Temporary ASP.NET Files \ website1 \ 7e2bf4c4 \加载4d1a1e05\App_Code.ch9yol_l.dll] log4net:DefaultRepositorySelector:程序集 [App_Code.ch9yol_l,Version=0.0.0.0,Culture=neutral,PublicKeyToken=null] 未指定 RepositoryAttribute。 log4net:DefaultRepositorySelector:使用存储库 [log4net-default-repository] ​​和存储库类型 [log4net.Repository.Hierarchy.Hierarchy] 的程序集 [App_Code.ch9yol_l,Version=0.0.0.0,Culture=neutral,PublicKeyToken=null] log4net:DefaultRepositorySelector:使用类型 [log4net.Repository.Hierarchy.Hierarchy] 创建存储库 [log4net-default-repository] log4net:XmlConfigurator:使用 .config 文件部分配置存储库 [log4net-default-repository] log4net:XmlConfigurator:应用程序配置文件为 [C:\Users\ScarryComp\Documents\Visual Studio 2008\WebSites\WebSite1\web.config] log4net:XmlConfigurator:配置存储库 [log4net-default-repository] log4net:XmlHierarchyConfigurator:配置更新模式[合并]。 log4net:XmlHierarchyConfigurator:记录器 [root] 级别字符串为 [ALL]。 log4net:XmlHierarchyConfigurator:记录器 [root] 级别设置为 [name="ALL",value=-2147483648]。 log4net:XmlHierarchyConfigurator:加载Appender [INFOFileAppender]类型:[log4net.Appender.FileAppender] log4net:XmlHierarchyConfigurator:将属性 [LockingModel] 设置为对象 [log4net.Appender.FileAppender+MinimalLock] log4net:XmlHierarchyConfigurator:将属性 [阈值] 设置为级别值 [全部] log4net:XmlHierarchyConfigurator:将属性 [文件] 设置为字符串值 [AOKlogs.txt] log4net:XmlHierarchyConfigurator:将属性 [AppendToFile] 设置为布尔值 [True] log4net: XmlHierarchyConfigurator: 参数[layout]指定子类型[log4net.Layout.PatternLayout] log4net: PatternParser: 转换器 [文字] 选项 [ ] 格式[min=-1,max=2147483647,leftAlign=False] log4net:XmlHierarchyConfigurator:将属性 [Layout] 设置为 PatternLayout 值 [log4net.Layout.PatternLayout] log4net:FileAppender:打开用于写入的文件 [C:\Users\ScarryComp\Documents\Visual Studio 2008\WebSites\WebSite1\AOKlogs.txt] 附加 [True] log4net:XmlHierarchyConfigurator:创建 Appender [INFOFileAppender] log4net:XmlHierarchyConfigurator:将名为 [INFOFileAppender] 的附加程序添加到记录器 [root]。 log4net:XmlHierarchyConfigurator:加载Appender [控制台]类型:[log4net.Appender.ConsoleAppender] log4net: PatternParser: 转换器 [消息] 选项 [] 格式 [min=-1,max=2147483647,leftAlign=False] log4net: PatternParser: 转换器 [换行符] 选项 [] 格式 [min=-1,max=2147483647,leftAlign=False] log4net:XmlHierarchyConfigurator:将属性 [ConversionPattern] 设置为字符串值 [%d %-5l - %m%n] log4net: PatternParser: 转换器 [d] 选项 [] 格式 [min=-1,max=2147483647,leftAlign=False] log4net:PatternParser:转换器[文字]选项[]格式[min = -1,max = 2147483647,leftAlign = False] log4net: PatternParser: 转换器 [l] 选项 [] 格式 [min=5,max=2147483647,leftAlign=True] log4net: PatternParser: 转换器 [文字] 选项 [ - ] 格式 [min=-1,max=2147483647,leftAlign=False] log4net: PatternParser: 转换器 [m] 选项 [] 格式 [min=-1,max=2147483647,leftAlign=False] log4net: PatternParser: 转换器 [n] 选项 [] 格式 [min=-1,max=2147483647,leftAlign=False] log4net:XmlHierarchyConfigurator:将属性 [Layout] 设置为对象 [log4net.Layout.PatternLayout] log4net:XmlHierarchyConfigurator:创建 Appender [控制台] log4net:XmlHierarchyConfigurator:将名为 [Console] 的附加程序添加到记录器 [root]。 log4net:XmlHierarchyConfigurator:层次结构阈值 []

我更改了添加的控制台附加程序,但我仍然在日志中看不到文本:(

更新 2: 文件附加器不起作用,但跟踪附加器似乎没问题。但是,如果 someboydy 可以解释文件附加程序可能会发生什么,那就太好了,这样问题仍然悬而未决

I'm trying to make log4net work using File Appender.

I use specified pattern layout for messages, but the problem is that I get no text in my log file. only '??' symbols

It seems that the the message text somehow gets corrupted before being written to file.

I'm using Visual Studio 2008 on windows Server 2008. The log4net is initialised in global.asax

here is my config for log4net

<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"></section>
. . .
<log4net debug="true">
    <appender name="INFOFileAppender" type="log4net.Appender.FileAppender">
        <lockingmodel type="log4net.Appender.FileAppender+MinimalLock"/>
      <threshold value="INFO" />  
      <file value="AOKlogs.txt" />
        <appendtofile value="true" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
      </layout>          
    </appender>
    <root>
        <level value="ALLL" />
        <appender-ref ref="INFOFileAppender" />
    </root>
  </log4net>

I've tried both rollingfile and simple file appender without luck.

UPDATE
I enabled debugging and configured log4net to write debug log to txt file. and here is what it says:

i enabled debugging log to txt file and here is what it says:

log4net: log4net assembly [log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821]. Loaded from [C:\Users\ScarryComp\AppData\Local\Temp\Temporary ASP.NET Files\website1\7e2bf4c4\4d1a1e05\assembly\dl3\c6bded9b\0086655c_d353c601\log4net.DLL]. (.NET Runtime [2.0.50727.4952] on Microsoft Windows NT 6.1.7600.0)
log4net: DefaultRepositorySelector: defaultRepositoryType [log4net.Repository.Hierarchy.Hierarchy]
log4net: DefaultRepositorySelector: Creating repository for assembly [App_Code.ch9yol_l, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]
log4net: DefaultRepositorySelector: Assembly [App_Code.ch9yol_l, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null] Loaded From [C:\Users\ScarryComp\AppData\Local\Temp\Temporary ASP.NET Files\website1\7e2bf4c4\4d1a1e05\App_Code.ch9yol_l.dll]
log4net: DefaultRepositorySelector: Assembly [App_Code.ch9yol_l, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null] does not have a RepositoryAttribute specified.
log4net: DefaultRepositorySelector: Assembly [App_Code.ch9yol_l, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null] using repository [log4net-default-repository] and repository type [log4net.Repository.Hierarchy.Hierarchy]
log4net: DefaultRepositorySelector: Creating repository [log4net-default-repository] using type [log4net.Repository.Hierarchy.Hierarchy]
log4net: XmlConfigurator: configuring repository [log4net-default-repository] using .config file section
log4net: XmlConfigurator: Application config file is [C:\Users\ScarryComp\Documents\Visual Studio 2008\WebSites\WebSite1\web.config]
log4net: XmlConfigurator: Configuring Repository [log4net-default-repository]
log4net: XmlHierarchyConfigurator: Configuration update mode [Merge].
log4net: XmlHierarchyConfigurator: Logger [root] Level string is [ALL].
log4net: XmlHierarchyConfigurator: Logger [root] level set to [name="ALL",value=-2147483648].
log4net: XmlHierarchyConfigurator: Loading Appender [INFOFileAppender] type: [log4net.Appender.FileAppender]
log4net: XmlHierarchyConfigurator: Setting Property [LockingModel] to object [log4net.Appender.FileAppender+MinimalLock]
log4net: XmlHierarchyConfigurator: Setting Property [Threshold] to Level value [ALL]
log4net: XmlHierarchyConfigurator: Setting Property [File] to String value [AOKlogs.txt]
log4net: XmlHierarchyConfigurator: Setting Property [AppendToFile] to Boolean value [True]
log4net: XmlHierarchyConfigurator: Parameter [layout] specified subtype [log4net.Layout.PatternLayout]
log4net: PatternParser: Converter [literal] Option [
  ] Format [min=-1,max=2147483647,leftAlign=False]
log4net: XmlHierarchyConfigurator: Setting Property [Layout] to PatternLayout value [log4net.Layout.PatternLayout]
log4net: FileAppender: Opening file for writing [C:\Users\ScarryComp\Documents\Visual Studio 2008\WebSites\WebSite1\AOKlogs.txt] append [True]
log4net: XmlHierarchyConfigurator: Created Appender [INFOFileAppender]
log4net: XmlHierarchyConfigurator: Adding appender named [INFOFileAppender] to logger [root].
log4net: XmlHierarchyConfigurator: Loading Appender [Console] type: [log4net.Appender.ConsoleAppender]
log4net: PatternParser: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: XmlHierarchyConfigurator: Setting Property [ConversionPattern] to String value [%d %-5l - %m%n]
log4net: PatternParser: Converter [d] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [literal] Option [ ] Format [min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [l] Option [] Format [min=5,max=2147483647,leftAlign=True]
log4net: PatternParser: Converter [literal] Option [ - ] Format [min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [m] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [n] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: XmlHierarchyConfigurator: Setting Property [Layout] to object [log4net.Layout.PatternLayout]
log4net: XmlHierarchyConfigurator: Created Appender [Console]
log4net: XmlHierarchyConfigurator: Adding appender named [Console] to logger [root].
log4net: XmlHierarchyConfigurator: Hierarchy Threshold []

I changed added Console appender but I still don't see text in my logs :(

UPDATE 2:
File appenders didn't work but trace appender appeared to be ok. However, that would be nice if someboydy could explain what could happen to file appenders so the question remains kinda opened

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风铃鹿 2024-10-15 08:31:18

我可以想象你有编码问题。 Log4net 默认使用 ANSI 编码,如果您的服务器(或服务)和您的计算机不使用相同的编码,您将无法读取文件中的文本。

您可以尝试像这样配置编码:

<appender name="INFOFileAppender" type="log4net.Appender.FileAppender">
    <encoding value="unicodeFFFE" />
    ...

I could imagine that you have an encoding problem. Log4net uses an ANSI encoding by default, if your server (or service) and your machine do not use the same encoding you would not be able to read the text in the file.

You could try to configure the encoding like this:

<appender name="INFOFileAppender" type="log4net.Appender.FileAppender">
    <encoding value="unicodeFFFE" />
    ...
征﹌骨岁月お 2024-10-15 08:31:18

您的级别值似乎错误,您可以尝试使用相同的配置吗?

<root>
    <level value="ALL" />
    <appender-ref ref="INFOFileAppender" />
</root>

Your level value seems to be wrong, can you try the same configuration with this instead ?

<root>
    <level value="ALL" />
    <appender-ref ref="INFOFileAppender" />
</root>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文