标签: enterprise-library

如何在企业库4.0中创建自定义日志过滤器?

我正在使用Enterprise Library 4.0,但我找不到有关创建自定义日志记录筛选器的任何文档.有没有人这样做或看过任何好的在线文档?

.net logging enterprise-library

2
推荐指数
1
解决办法
1846
查看次数

C#DbCommand循环

我有一个文件集合,对于我将在事务中使用Dbcommand调用SP的每个文件.

例如:

  DbCommand insert = db.GetStoredProcCommand("Insert");
  db.AddInParameter(insert, "FileName", System.Data.DbType.String, 
      ID + ".xml");
  db.ExecuteNonQuery(insert, transaction); 
Run Code Online (Sandbox Code Playgroud)

我的问题是如何把它放在循环中?

下面的答案不起作用,但感谢其他伟大的代码示例.问题是db没有可以操作的Parameters集合.校验...

http://msdn.microsoft.com/en-us/library/microsoft.practices.enterpriselibrary.data.sql.sqldatabase_members%28BTS.10%29.aspx

我这样声明我的数据库:

SqlDatabase db = new SqlDatabase(this.ConnectionString );
Run Code Online (Sandbox Code Playgroud)

c# enterprise-library

2
推荐指数
1
解决办法
4022
查看次数

在ASP.NET中使用企业库异常处理应用程序块 - 代码审查

我正在构建的ASP.NET应用程序中实现企业库异常处理应用程序块.我打算通过在Global.asax.cs中放置以下代码来处理未捕获的应用程序异常:

protected void Application_Error()
    {
        Exception error = Server.GetLastError();
        Exception errorToThrow;

        if (ExceptionPolicy.HandleException(error, "Application Error", out errorToThrow))
        {
            if (errorToThrow != null)
                throw errorToThrow;
        }
        else
            Server.ClearError();
    }
Run Code Online (Sandbox Code Playgroud)

我相信这将有助于处理策略的各种后处理操作(None,NotifyRethrow,ThrowNewException),但我想知道是否有人发现此实现存在重大问题.

asp.net enterprise-library exception-handling

2
推荐指数
1
解决办法
7676
查看次数

如何使用类实例、对象或类型锁定 .NET

我想知道你如何知道何时锁定整个类型

lock (typeof(MyClass))
{
...
}
Run Code Online (Sandbox Code Playgroud)

或一个实例

lock (this)
{
...
}
Run Code Online (Sandbox Code Playgroud)

或一个物体

lock (this._lockObj)
{
...
}
Run Code Online (Sandbox Code Playgroud)

我问这个问题是因为我有一个静态类,它是 Enterprise Library 5 的简单包装器,并且可由多个组件从可能不同的线程访问。WriteLog() 方法被锁定。我用的是type来锁的。

.net c# multithreading enterprise-library

2
推荐指数
1
解决办法
3707
查看次数

实体框架 - System.IndexOutOfRangeException

我正在使用查询 SQL Server 2008 数据库的实体框架 4.1。不幸的是,我们经常遇到以下异常:

<ExceptionType>System.IndexOutOfRangeException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
  <Message>Index was outside the bounds of the array.</Message>



at System.Data.SqlClient.SqlDataReader.ReadColumnHeader(Int32 i)
   at System.Data.SqlClient.SqlDataReader.IsDBNull(Int32 i)
   at System.Data.Common.Internal.Materialization.Shaper.ErrorHandlingValueReader`1.GetValue(DbDataReader reader, Int32 ordinal)
   at System.Data.Common.Internal.Materialization.Shaper.GetPropertyValueWithErrorHandling[TProperty](Int32 ordinal, String propertyName, String typeName)
   at lambda_method(Closure , Shaper )
   at System.Data.Common.Internal.Materialization.Shaper.HandleEntityAppendOnly[TEntity](Func`2 constructEntityDelegate, EntityKey entityKey, EntitySet entitySet)
   at lambda_method(Closure , Shaper )
   at System.Data.Common.Internal.Materialization.Coordinator`1.ReadNextElement(Shaper shaper)
   at System.Data.Common.Internal.Materialization.Shaper`1.SimpleEnumerator.MoveNext()
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
   at System.Linq.Queryable.First[TSource](IQueryable`1 source)
   at OnlineSelfService.Business.ContentServiceBusiness.GetPageContent(Int32 pageId)</StackTrace>
Run Code Online (Sandbox Code Playgroud)

实际的示例代码:

//Caller
  public EmployeeEntity GetEmployeeDetail(int employeeID)
    {
         IQueryable<Employee> result=null;
         if (myCaching.Contains("Employee"))
            { …
Run Code Online (Sandbox Code Playgroud)

linq caching entity-framework enterprise-library c#-4.0

2
推荐指数
1
解决办法
2903
查看次数

使用企业库验证块进行复杂对象验证

我正在使用企业库验证.

我有类似下面的课程

 public class Customer
    {

        public int Id { get; set; }
        [NotNullValidator(MessageTemplate = "{1} is null")]
        public string FirstName { get; set; }
        [NotNullValidator(MessageTemplate = "{1} is null")]
        public string Surname { get; set; }

    }

  public class Order
    {

        public int Id { get; set; }
        [NotNullValidator(MessageTemplate = "{1} is null")]
        public Customer Customer { get; set; }

    }
Run Code Online (Sandbox Code Playgroud)

当我使用订单对象和姓氏和名字是空的验证应该启动,但它没有.

我究竟做错了什么?

注意:我在WCF中使用它

.net enterprise-library

1
推荐指数
1
解决办法
2197
查看次数

Unity vs EntLib?

我已经使用EntLib一段时间了,最​​近发现了Unity.乍一看,它似乎可以处理EntLib所做的大部分工作,但看起来重量更轻.

哪一天推荐,MVVM架构,以及一个的优点/缺点?

谢谢.

enterprise-library unity-container mvvm

1
推荐指数
1
解决办法
309
查看次数

使用Enterprise Library 5.0数据访问问题

这可能是一个非常简单的问题,但或多或​​少,我要求这样,我可以围绕数据访问块如何打开和关闭连接.

首先,我使用了类似企业库的东西大约10年,并在实体等之间来回切换.

无论如何,当我使用Database类的CreateDatabase()函数时,这是否会立即打开与数据库的连接,还是在我使用ExecuteReader之类的实际调用时打开连接?

它如何处理关闭连接?在DAL中使用连接后,我是否必须明确调用连接?在完成Reader等操作后,企业库如何确保连接已关闭?

此外,打开和关闭连接的最佳做法是什么?如果CreateDatabase立即打开连接?有一小部分代码可以分享吗?

c# asp.net enterprise-library asp.net-mvc-3

1
推荐指数
1
解决办法
2727
查看次数

企业库未正确记录严重性

我对企业库5有问题。它正在将要写入的所有信息写入事件日志,但是,它不遵守我配置的严重性设置。

我的异常处理配置块如下所示:

<exceptionHandlers>
  <add name="Logging Exception Handler"
       type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging...,"
       logCategory="General"
       eventId="10000"
       severity="Critical"
       title="My unknown error"
       formatterType="Micros...ExceptionFormatter, Micros...ExceptionHandling"
       priority="0" />
</exceptionHandlers>
Run Code Online (Sandbox Code Playgroud)

我的事件日志侦听器模板以以下内容开头:

Severity: {severity}{newline}
Run Code Online (Sandbox Code Playgroud)

事件日志条目记录为“错误”,而不是“严重”,但是实际记录的消息包含文本“严重性:严重”

是否有关于我实际上如何将异常记录为Critical的指针而不必实际编写自己的异常处理程序/格式化程序的任何指针?

logging enterprise-library event-log enterprise-library-5

1
推荐指数
1
解决办法
1934
查看次数

在EntLib中登录/注销

配置文件中是否有一个设置可以在EntLib中打开或关闭日志记录.有帖子显示如何以编程方式执行此操作,但我有兴趣通过配置文件执行此操作.

我正在使用EntLib 5.

这是配置

 <loggingConfiguration name="" tracingEnabled="true" defaultCategory="General">
    <listeners>
        <add name="Event Log Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            source="Enterprise Library Logging" formatter="Text Formatter"
            log="" machineName="." traceOutputOptions="None" />
        <add name="Flat File Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            fileName="c:\\Log\\wclog.log" header=""
            formatter="Text Formatter" traceOutputOptions="DateTime, Timestamp" />
    </listeners>
    <formatters>
        <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            template="Timestamp:{timestamp}  Method: {title}, {category} {message}"
            name="Text Formatter" />
    </formatters>
    <categorySources>
        <add switchValue="All" name="General">
            <listeners>
                <add name="Flat File Trace …
Run Code Online (Sandbox Code Playgroud)

c# enterprise-library

1
推荐指数
1
解决办法
6850
查看次数