开发者

log4net message text problem

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 writ开发者_开发知识库ten 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


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" />
    ...


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜