草庐IT

Creating-and-configuring-log-stre

全部标签

c# - 错误 : ExecuteReader requires an open and available Connection. 连接的当前状态为打开

我有下面带有DataHelperClass的mvc4网站来执行查询。我的问题有时是,网站以异常为标题。我使用block来处理SqlCommand和SqlDataAdapter但没有成功。请帮助我,对不起我的英语。try{if(_conn.State==ConnectionState.Closed)_conn.Open();using(SqlCommandsqlCommand=newSqlCommand(query,_conn)){sqlCommand.CommandType=CommandType.StoredProcedure;if(parameters!=null)sqlComma

c# - 统一: Change default lifetime manager for implicit registrations and/or disable them

Unity容器将自动解析它可以自行识别的任何类型,无需手动注册。这在某些方面很好,但我遇到的问题是它使用TransientLifetimeManager来解决这种类型的问题,而我几乎总是想要一个ContainerControlledLifetimeManager。当然,我仍然可以手动将我的类型注册为单例,但如果我忘记了,应用程序将成功启动,而不是在启动时出现未处理的异常,并且一切似乎都正常工作。但最终会出现错误,可能非常微妙,难以诊断,因为存在一个类型的多个实例,这意味着是一个单例。所以我的问题是:有没有一种方法可以指定不同的默认生命周期管理器或完全禁用默认的自动解析行为并将容器限制为

c# - 无法加载文件或程序集 log4net

我已将log4net添加到我的项目中,它在我的机器上运行良好,但是当我将我的应用程序的发布版本发送给我的同事时,他收到此FileNotFoundException:Couldnotloadfileorassembly'log4net,Version=1.2.13.0,Culture=neutral,PublicKeyToken=669e0ddf0bb1aa2a'但奇怪的是,在我的app.config中我什至没有使用上面版本的log4net: 最佳答案 遇到了同样的问题。LinqToExcel库使用不同版本的log4net。解决方法:

c# - 如何为类库包含 log4net?

我想将日志记录功能实现到一个类库中,该类库本身在Web服务中被引用。我尝试添加app.config并完成所需的一切,但似乎在抛出异常时,log4net什么都不做。我的应用程序配置在AssemblyInfo.cs中:[assembly:log4net.Config.XmlConfigurator(ConfigFile="app.config")]在LogManager.cs中:privatestaticreadonlyILogLog=log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);publ

c# - "Both use the XML type name X, use XML attributes to specify a unique XML name and/or namespace for the type"怎么解决?

我有以下枚举定义...namespaceItemTable{publicenumDisplayMode{Tiles,Default}}namespaceEffectiveItemPermissionTable{publicenumDisplayMode{Tree,FullPaths}}...然后我有以下类(class)...publicclassTablewhereTDisplayMode:struct{//publicpublicTDisplayModeDisplayMode{get{returnmDisplayMode;}set{mDisplayMode=value;}}//pri

c# - Log4net - 使用继承时的最佳策略

我在我的应用程序中集成了log4net。我有一些帮助方法来帮助记录调用log4net。重构时,我打算将这些方法移到基类中,这样代码就不会在其他派生类中重复。在没有继承模型的情况下,以下在每个类中都能正常工作privatestaticreadonlyILogLog=LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);将以上内容放在基类中将返回声明类型作为基类而不是派生类。将此声明移至基类的最佳方法是什么?目前,我可以想到几种方法来实现这一点,但没有发现它们是最佳的。 最佳答案

c# - 类型 'TestClassAttribute' 存在于 'Microsoft.VisualStudio.QualityTools.UnitTestFramework and ' Microsoft.VisualStudio.TestPlatform.TestFramework

更新测试项目NuGet后出现此错误:Thetype'TestClassAttribute'existsinboth'Microsoft.VisualStudio.QualityTools.UnitTestFramework,Version=10.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a'and'Microsoft.VisualStudio.TestPlatform.TestFramework,Version=14.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a'

c# - 如何使用 log4net 使用 Threadpool 线程记录正确的上下文?

我试图找到一种方法来从一堆线程中记录有用的上下文。问题是很多代码是在通过线程池线程到达的事件上处理的(据我所知),因此它们的名称与任何上下文无关。这个问题可以用下面的代码来演示:classProgram{privatestaticreadonlylog4net.ILoglog=log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);staticvoidMain(string[]args){newThread(TestThis).Start("ThreadA")

c# - GetMonthName : Valid values are between 1 and 13, 包括在内。为什么?

我不小心将0传递给DateTimeFormatInfo的GetMonthName方法:DateTimeFormatInfoinfo=newDateTimeFormatInfo();varmonthName=info.GetMonthName(0);并得到一个System.ArgumentOutOfRangeException错误消息:有效值在1到13之间,包括在内。传入1到12将返回“January”到“December”,但传入13将返回一个空字符串。我明白为什么月份数字不是零索引的,但是第13个月是做什么用的? 最佳答案 这是因

c# - 使用 "Expression Bodied Functions and Properties"有什么好处

这个问题在这里已经有了答案:Expression-bodiedfunctionmembersefficiencyandperformanceinC#6.0(2个答案)关闭6年前。我确实看到很多人使用该新功能,但使用这些表达式有什么好处?Examples:publicoverridestringToString()=>string.Format("{0},{1}",First,Second);publicstringText=>string.Format("{0}:{1}-{2}({3})",TimeStamp,Process,Config,User);这个问题不同于thisone,因为