rebus log4net的日期错误

时间:2014-02-18 14:11:06

标签: c# log4net log4net-configuration rebus

当我在消息类型的处理程序中抛出异常时,会使用UTCDate记录异常,但这应该是计算机日期。

奇怪的是它正确记录它然后登录错误,因此多个日志消息被添加到文件中。这不是必需的!

以下日志中的正确时间是2014-02-18 14:......错误的时间是18-02-2014 13:.... 我不需要错误的时间日志 经度:

2014-02-18 14:08:43,616 WARN Rebus 1 worker 1 Rebus.Bus.RebusBus - User exception in Rebus 1 worker 1: System.IO.IOException: Error writing to file ---> System.UnauthorizedAccessException: Access to the path 'X' is denied.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
   at System.IO.FileStream..ctor(String path, FileMode mode)
   at X.Y(X X, X X, X X) in X:line 538
   --- End of inner exception stack trace ---
   at X.Y(X X, X X, X X) in X:line 546
   at Rebus.Bus.Dispatcher.DispatchToHandler[TMessage](TMessage message, IHandleMessages`1 handler)

18-02-2014 13:08:43:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.IOException: Error writing to file ---> System.UnauthorizedAccessException: Access to the path 'X' is denied.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
   at System.IO.FileStream..ctor(String path, FileMode mode)
   at X.Y(X X, X X, X X) in X:line 538
   --- End of inner exception stack trace ---
   at X.Y(X X, X X, X X) in X:line 546
   at Rebus.Bus.Dispatcher.DispatchToHandler[TMessage](TMessage message, IHandleMessages`1 handler)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Rebus.Bus.Dispatcher.Dispatch[TMessage](TMessage message)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at Rebus.Bus.Worker.DoTry()
   at Rebus.Bus.Worker.TryProcessIncomingMessage()
   at Rebus.Bus.Worker.MainLoop()

Log4NetConfiguration:

<log4net>
    <logger name="NHibernate">
      <level value="ERROR" />
    </logger>
    <logger name="NHibernate.SQL">
      <level value="ERROR" />
    </logger>
    <!-- The DebugFileAppender writes all messages to a log file-->
    <appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
      <file value="X" />
      <appendToFile value="true" />
      <maximumFileSize value="10000KB" />
      <maxSizeRollBackups value="10" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date %level %thread %logger - %message%newline" />
      </layout>
    </appender>
    <appender name="ColoredConsoleAppender" type="log4net.Appender.ColoredConsoleAppender">
      <mapping>
        <level value="ERROR" />
        <forecolor value="Red" />
      </mapping>
      <mapping>
        <level value="DEBUG" />
        <forecolor value="Yellow" />
      </mapping>
      <mapping>
        <level value="INFO" />
        <forecolor value="White" />
      </mapping>
      <layout type="log4net.Layout.PatternLayout">
        <conversionpattern value="%date [%thread] %logger %-5level - %message%newline" />
      </layout>
    </appender>
    <appender name="EventLogAppender" type="log4net.Appender.EventLogAppender">
      <!--<param name="LogName" value="X" />-->
      <param name="ApplicationName" value="X" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date %newline %type %newline %method %newline %message %newline %exception" />
      </layout>
      <filter type="log4net.Filter.LevelRangeFilter">
        <levelMin value="WARN" />
        <levelMax value="FATAL" />
      </filter>
    </appender>
    <root>
      <!-- add other appenders here and the log messages will be sent to every listed appender -->
      <appender-ref ref="EventLogAppender" />
      <appender-ref ref="RollingFile" />
      <appender-ref ref="ColoredConsoleAppender" />
    </root>
  </log4net>

Rebus日志记录设置:

var rebusConfigurer = Configure.With(new WindsorContainerAdapter(container))
    .Logging(l => l.Log4Net()).Transport(t => t.UseMsmqAndGetInputQueueNameFromAppConfig())
    .MessageOwnership(o => o.FromRebusConfigurationSection())
    .X(s => s.StoreInSqlServer(() => (SqlConnection)container.Resolve<ISession>().Connection, "X", "X"))
    .SpecifyOrderOfHandlers(s => s.Use(new MyMessageHandlerInspector()));

Rebus抓住了异常

throw new IOException("Error writing to file", exception);

如何阻止或配置rebus如何记录此内容?正如您在日志中看到的,一些rebus日志记录是可以的,而另一些则不是。

1 个答案:

答案 0 :(得分:2)

Rebus跟踪捕获的异常,包括重试之间的时间戳,通过保留Timed<Exception>个实例的列表来生成dnoe,并且用于使用DateTime.UtcNow初始化每个异常。

我已经在Rebus 0.57.0中更改了它但使用DateTime.Now,因为我同意你的说法没有意义 - 或者至少它与Log4Net的时间戳一起看起来很奇怪:)