为什么log4net会随机停止使用SignalR进行记录?

时间:2016-12-14 11:34:25

标签: c# logging signalr log4net

我有两台SignalR服务器使用redis背板并使用log4net。当我启动应用程序时,一切都很好,日志文件在两台服务器上都正确写入。但有时,日志文件不再写入,内部调试日志说:

<log4net> <appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender" > <param name="File" value="C:\myLogPath\SignalR\log.txt" /> <lockingModel type="log4net.Appender.FileAppender+MinimalLock" /> <appendToFile value="true" /> <rollingStyle value="Date" /> <maxSizeRollBackups value="-1" /> <maximumFileSize value="100MB" /> <datePattern value="ddMMyyyy" /> <staticLogFileName value="true" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date - %-5level - %message%newline" /> </layout> </appender> <root> <level value="ALL" /> <appender-ref ref="LogFileAppender" /> </root> </log4net>

...每次新行都必须记录(超过100次秒 - 这是预期的记录速率),没有任何错误消息,无论是之前还是之后。问题同时发生在两台服务器上 - 记录的最后一行完全相同;这就是我写SignalR服务器的原因是使用了背板。这是我的log4net.config:

maxSizeRollBackups

我确信这些文件没有被汇总,因为maximumFileSize设置为-1(相当于无限),而log.txt文件的权重大约为16MB,远离MinimalLock 。我尝试使用和不使用Startup,但没有任何效果。

这是 public class Startup { public void Configuration(IAppBuilder app) { Common.Logger.Start(ConfigurationManager.AppSettings["pathLog4net"]); Common.Logger.Info("Démarrage SignalR"); //Connect to backplane, make some DI, singletons initialisations... Common.Logger.Info("Mapping"); app.Map("/signalr", map => { map.UseCors(CorsOptions.AllowAll); var hubConfiguration = new HubConfiguration { EnableJSONP = true, EnableDetailedErrors = HttpContext.Current.IsDebuggingEnabled }; map.RunSignalR(hubConfiguration); }); } } 类,我在其中启动log4net:

Common.Logger

...和 public static class Logger { private static log4net.ILog Log { get; set; } static Logger() { Log = log4net.LogManager.GetLogger(typeof(Logger)); } public static void Start(string path) { log4net.Config.XmlConfigurator.Configure(new FileInfo(path)); } public static void Error(object msg) { Log.Error(msg); } public static void Info(object msg) { Log.Info(msg); } } 类,它封装了log4net:

Logger.Info

在每个集线器方法中调用Opening file [...] append [True]方法,所以我想知道它是否可能是并发问题,但是log4net doc说明它是安全的 - 虽然我不知道它在哪个级别;并且问题恰好在同一时间发生在第二个SignalR上。每次重新启动应用程序时,日志都会在未定义的时间内运行,然后再次停止。

我尝试更改log4net配置,禁用内部日志,但没有任何作用。我不知道该怎么办......为什么日志会停止?为什么log4net无法附加到文件,即使内部日志显示Full control?如果有人有一些想法,我将永远感激:)

编辑:显然权利设置正确 - 我很高兴我羞愧地试过Everyonefunction text_to_hyperlink(input_id) { var text_entry = document.getElementById(input_id); var text_selected; // for IE if (document.selection != undefined) { text_entry.focus(); var sel = document.selection.createRange(); text_selected = sel.text; } // others browsers else if (text_entry.selectionStart != undefined) { var selection_pos_start = text_entry.selectionStart; var selection_pos_end = text_entry.selectionEnd; text_selected = text_entry.value.substring(selection_pos_start, selection_pos_end); selection_prefix = text_entry.value.substring(0, selection_pos_start); selection_sufix = text_entry.value.substring(selection_pos_end, text_entry.length ); } text_entry.value = selection_prefix + '<a href="' + text_selected + '">' + text_selected + '</a>' + selection_sufix; } ......

1 个答案:

答案 0 :(得分:1)

Sooooo ......实际上这是一个简单的问题。我的网站正在使用业务层,他们有自己的log4net实例,使用相同的配置文件...所以这只是一个锁定错误。

我更改了signalr日志记录封装以使用业务层的log4net,现在一切都很好。

很高兴知道:当出现锁定错误时,log4net似乎只在首次尝试写入该文件时才记录它。

相关问题