我在asp.net中使用Microsoft Enterprise Library 3.1进行异常处理,这些错误存储在系统的事件查看器中.
我需要使用Enterprise Library将这些错误存储在日志文件中,而不是事件查看器.
我以前使用过log4net,但我现在的雇主使用Enterprise Library应用程序块.我之前已经为我的核心日志记录类开发了单元测试,如下所示,并且想知道是否有人知道以下针对日志记录应用程序块的OneTimeSetup代码(对于长代码帖子而言):
public abstract class DataGathererBase
{
public readonly log4net.ILog logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public void CollectData()
{
this.LogDebug("Initialize started");
}
public static class Logger
{
private static LoggingSettings settings = LoggingSettings.GetLoggingSettings(new SystemConfigurationSource());
static Logger()
{
log4net.Config.XmlConfigurator.Configure();
}
public static void LogDebug(this DataGathererBase current, string message)
{
if (current.logger.IsDebugEnabled)
{
current.logger.Debug(string.Format("{0} logged: {1}", current.GetType().Name, message));
}
}
}
[TestFixture]
public class LoggerTests:DataGathererBase
{
private ListAppender appender;
private static ILog log;
[TestFixtureSetUp]
public void OneTimeSetup()
{
appender = new ListAppender();
appender.Layout = …Run Code Online (Sandbox Code Playgroud) 我正在使用MS EnterpriseLibrary.Logging并且工作正常但日志文件放在程序可执行文件目录中.
如何将我的日志文件放在单个用户的applicationData文件夹中?
我正在谈论的文件夹是你通过调用获得的文件夹:
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
Run Code Online (Sandbox Code Playgroud) 我正在使用基于多层SOA的企业应用程序来处理所有复杂的业务逻辑.许多业务验证需要来自数据库的大量支持数据,这会降低性能.并发用户的数量大约是1000.客户端是多层的WinForms.
我们正在考虑几乎所有的企业库块.
验证应用程序块
我正在使用Ent Lib 5登录事件日志.当我在Windows 7机器上运行应用程序时,一切正常.但是当我在WindowsServer 2008上部署它时,它就会停止记录.它不会向事件日志写任何内容.在两台机器上安装了Ent Lib 5.
所以你怎么看?可能是什么问题?
我有一个单独的接口,这是由2个类使用.我正在使用统一配置来基于接口识别实例.
现在我想知道如何注册这些类型,以便我可以基于单个接口本身调用适当的实现.
调用Select函数时出现以下错误:
传入的表格数据流(TDS)远程过程调用(RPC)协议流不正确.表值参数3("@ SearchTableVar"),第0行,第0列:数据类型0xF3(用户定义的表类型)具有指定的非零长度数据库名称.表值参数不允许使用数据库名称,只有模式名称和类型名称有效.
C#代码
//DTO
public class SP_SearchEntity_Result
{
public string ID { get; set; }
public string NAME { get; set; }
}
//Businesslogic
public IQueryable Select(int PageIndex, int PageSize, List<KeyValuePair<string, string>> SearchBy, List<KeyValuePair<string, System.Data.SqlClient.SortOrder>> SortBy)
{
SqlDatabase obj = (SqlDatabase)DatabaseFactory.CreateDatabase();//System.Configuration.ConfigurationManager.ConnectionStrings["MySqlServer"].ConnectionString
return obj.ExecuteSprocAccessor<SP_SearchEntity_Result>("SP_SearchEntity", PageIndex, PageSize, SearchBy.ToDataTable(), SortBy.ToDataTable()).AsQueryable<SP_SearchEntity_Result>();
}
//Extension methods
public static DataTable ToDataTable(this List<KeyValuePair<string, string>> source)
{
DataTable dataTable = new DataTable("Test");
dataTable.Columns.Add("KEY",typeof(System.String));
dataTable.Columns.Add("VALUE", typeof(System.String));
foreach (KeyValuePair<string, string> data in source)
{
var dr = dataTable.NewRow(); …Run Code Online (Sandbox Code Playgroud) 我已经创建了一个非常基本的Logging块和异常处理块.在我的代码中,我去测试异常处理(我知道Logging块工作),具体如下:
public void RunScriptClean()
{
try
{
throw new FileNotFoundException();
}
catch (FileNotFoundException ex)
{
var b = ExceptionPolicy.HandleException(ex, "Logging Policy");
if (b)
throw;
}
}
Run Code Online (Sandbox Code Playgroud)
但是,在catch块的第一行,我得到了这个冗长的异常,我的应用程序崩溃了:
Exception occured: The current build operating (build key Build Key [Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyImpl, Logging Policy]) failed: The type 'Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' cannot be resolved. Please verify the spelling is correct or that the full type name is provided. (Strategy type ConfiguredObjectStrategy, index 2).
当它说类型无法解决时,我完全不知道它指的是什么.我添加了对Microsoft.Practices.EnterpriseLibrary.Common/ExceptionHandling/Logging和Ms.Practices.ObjectBuilder2的引用.这一课using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling包括在顶部.
添加了查看我的AppConfig文件的配置工具的屏幕截图:

我确定我遗漏了一些基本的东西,但很难找到EAB 4.1的教程 - CodeProject对于原始版本有很多东西,但是我不能做很多...
编辑我尝试创建一个新的Formatter并命名它, …
我正在尝试构建重试,HttpClient DelegatingHandler以便将诸如503 Server Unavailable和超时之类的响应视为瞬态故障并自动重试.
我从http://blog.devscrum.net/2014/05/building-a-transient-retry-handler-for-the-net-httpclient/的代码开始,该代码适用于该403 Server Unavailable案例,但不处理超时作为短暂的失败.不过,我喜欢使用Microsoft瞬态故障处理块来处理重试逻辑的一般想法.
这是我目前的代码.它使用自定义Exception子类:
public class HttpRequestExceptionWithStatus : HttpRequestException {
public HttpRequestExceptionWithStatus(string message) : base(message)
{
}
public HttpRequestExceptionWithStatus(string message, Exception inner) : base(message, inner)
{
}
public HttpStatusCode StatusCode { get; set; }
public int CurrentRetryCount { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这里是瞬态故障检测器类:
public class HttpTransientErrorDetectionStrategy : ITransientErrorDetectionStrategy {
public bool IsTransient(Exception ex)
{
var cex = ex as HttpRequestExceptionWithStatus;
var isTransient = cex != null …Run Code Online (Sandbox Code Playgroud) public void updateSkills(DataTable candidateSkillSets)
{
string sqlCommand = "Sp_Candidate";
DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);
db.AddInParameter(dbCommand, "candidateSkillSets",DbType.Object, candidateSkillSets);
db.ExecuteNonQuery(dbCommand);
}
Run Code Online (Sandbox Code Playgroud)
我有一个像上面这样的方法,这里我通过添加参数将数据表传递给存储过程."DbType.Object"没有采用数据表类型.我知道在ADO中我们可以使用"SqlDbType.Structured",但对于企业库,它不起作用.我需要用什么呢?
执行命令时出现以下错误
"传入的表格数据流(TDS)远程过程调用(RPC)协议流不正确.参数1("@candidateSkillSets"):数据类型0x62(sql_variant)具有类型特定元数据的无效类型."
c# ×5
asp.net ×3
logging ×3
.net ×1
.net-3.5 ×1
architecture ×1
frameworks ×1
soa ×1
soap-client ×1
sql ×1
unit-testing ×1
winforms ×1