我想log4net的和ELMAH工作。我試圖把代碼一起AppHost.cs:ServiceStack記錄設置
public class AppHost : AppHostBase {
//Tell ServiceStack the name and where to find your web services
public AppHost() : base("Backbone.js TODO", typeof(TodoService).Assembly) { }
public override void Configure(Funq.Container container) {
//...
//Log4Net 1.2.11
log4net.Config.XmlConfigurator.Configure(new FileInfo("log4net.config"));
container.Register(x => new Log4NetFactory(true));
//Elmah
container.Register(x => new ElmahLogFactory(container.Resolve<Log4NetFactory>()));
LogManager.LogFactory = container.Resolve<ElmahLogFactory>();
container.Register<ILog>(x => LogManager.GetLogger(GetType()));
//...
}
Log4net.config,這也是目前只是一個控制檯記錄...
<?xml version="1.0" encoding="utf-8" ?>
<log4net debug="true">
<appender name="TraceAppender" type="log4net.Appender.TraceAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%method %-5level - %message%newline"/>
</layout>
</appender>
<root>
<level value="DEBUG"/>
<appender-ref ref="TraceAppender"/>
</root>
</log4net>
那麼無論是必需的記錄:
ILog Logger {get; set;} //injected by ioc
//...
Logger.Info("Print something");
的Logger.Info("....");
線被稱爲沒有錯誤,但既不log4net的也不ELMAH正在打印任何輸出在我的代碼的上方。如果你有經驗,建立log4net的或與ELMAH ServiceStack,請你指出我做了什麼錯?
編輯
改變了FileInfo的完整路徑,它的工作是斯特凡艾格里建議!
或單擊項目log4net.config xml文件,在屬性框中
「複製到輸出 - >複製,如果新」
這將做,太。
然後,像這樣出現:
Auto-attach to process '[11308] w3wp.exe' on machine 'Desktop' succeeded.
//... printing info now ...
Backbone.Todos.AppHost: Info INFO - TodoService OnGet
//... but then after a coffee break ...
log4net: Hierarchy: Shutdown called on Hierarchy [log4net-default-repository]
// ... Oops, no longer printing any log ...
這似乎是Web應用程序去關閉本身在閒置一段時間後。然後log4net無法重新啓動,當我點擊Web應用程序...任何想法如何防止這種情況?
EDIT 2
切換到NLOG,從此過上幸福......
完整路徑是工作!謝謝!問題進一步發展。請參閱編輯。 – Tom