我们使用 Enterprise Library 4.1 进行日志记录(和异常处理/加密)。
有谁知道在运行时确定配置的日志记录级别的好方法吗?我编写了一个 LogUtility 类来进行日志记录调用,并按照以下示例调用它:
LogUtility.LogVerbose(
string.Format("Processing event {0}", currentEvent.EventIDImported),
MethodBase.GetCurrentMethod().Name,
this.GetType().Name
);
Run Code Online (Sandbox Code Playgroud)
我知道它实际上不会被记录到文件中,除非将日志记录级别设置为适当的级别,在我的情况下是在 app.config 中。但我真的不希望方法参数,即方法和类型名称,以及在某些情况下记录的实际字符串,除非绝对必要,否则会被评估。
这似乎是一个合理的担忧吗?我们的应用程序可以有数千万次迭代和记录点。如果可能,我想根据配置的日志级别设置一个标志,并在调用上述方法之前进行检查。
编辑 - 我想就上面的例子而言,我可以在每次调用时硬编码方法和类型名称。但我还是想知道是否有一种确定水平的方法。
我正在将解决方案从 .NET Framework 4.7.1 迁移到 .NET Core 2.1,并且遇到了 Enterprise Library 6 的问题(使用 EnterpriseLibrary.Data.NetCore Nuget Package)
我正在尝试从连接字符串创建数据库并将其注册到 Autofac。
原始代码如下所示:
builder.Register(c => new DatabaseProviderFactory().Create(DefaultConnection) as SqlDatabase).InstancePerLifetimeScope();
Run Code Online (Sandbox Code Playgroud)
其中DefaultConnection是表示连接字符串的字符串常量web.config。
在web.config我有:
<configSections>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data" requirePermission="true" />
</configSections>
<dataConfiguration defaultDatabase="DefaultConnection" />
<connectionStrings>
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="*****************" />
</connectionStrings>
Run Code Online (Sandbox Code Playgroud)
这很好用。
在我的 .NET Core 2.1 解决方案中,我使用以下代码
builder.Register(_ => new DatabaseProviderFactory().Create(Constants.DefaultConnection) as SqlDatabase).InstancePerLifetimeScope();
Run Code Online (Sandbox Code Playgroud)
但这会引发以下异常:
The connection string for the database 'DefaultConnection' does not exist or does not have a valid provider. …Run Code Online (Sandbox Code Playgroud) c# migration enterprise-library asp.net-core-mvc asp.net-core
使用Enterprise Library 3.1 May 2007版本时出现此错误.我们正在开发一个产品,并在Subversion Trunk目录下有一个公共的lib目录
<>\Trunk\Lib \我们将所有第三方DLL放入其中.在其中我们有Microsoft\EnterpriseLibrary\v3.1,其中我们从\ Program Files\Microsoft Enterprise Library May2007\bin复制了所有dll.一切正常,直到其中一个开发人员在这台机器上安装了源代码.在源代码安装结束时复制了一些dll,一旦完成,他就无法再运行该项目了.他总是得到这个错误
'Microsoft.Practices.EnterpriseLibrary.Data,Version = 3.1.0.0,Culture = neutral,PublicKeyToken = null'或其依赖项之一.定位的程序集的清单定义与程序集引用不匹配.(HRESULT异常:0x80131040)'
这里有什么问题?我认为当安装源代码时,它应该构建所有内容并复制到源代码父目录中的bin目录中.我们还将Dll从Microsoft Enterprise Library May 2007\bin目录复制到我们的产品开发目录中,并引用我们的项目,并将copylocal标志设置为true.
有人可以帮我从这里出去吗
RK
我试图想出一个可以为null的属性验证,比如int.
例
[RangeValidator(0, RangeBoundaryType.Inclusive, 1, RangeBoundaryType.Inclusive)]
int? Age { get; set; }
Run Code Online (Sandbox Code Playgroud)
但是,如果我设置Age为null验证失败,因为它不在范围内,我知道我也需要一个[ValidatorComposition(CompositionType.Or)],但我还应该使用什么呢?
下面的代码使用Microsoft的企业库日志记录应用程序块。您如何使其“更好”?
using Microsoft.Practices.EnterpriseLibrary.Logging;
class Program
{
static void Main(string[] args)
{
try
{
// Trying to write some data to the DB
...
}
catch (Exception ex)
{
LogHelper.LogException(ex, "Trying to write to the DB");
}
}
}
public class LogHelper
{
public static void LogException(Exception ex, string exceptionType)
{
try
{
// Simplified version, only logging the message
Logger.Write(exceptionType);
}
catch
{
// What do you do here???
}
}
}
Run Code Online (Sandbox Code Playgroud) 有谁知道微软企业库的未来?最新版本于2008年10月发布; 它会继续使用吗?或者我应该留意另一个同等的图书馆?
我正在使用Enterprise Library 3.1来记录某些Web应用程序的异常.应将所有异常写入Errors.xml应用程序运行的同一服务器上的单个XML文件(例如).有时这个问题除了Errors.xml我看到的文件名称如下:7b53e14b-4b92-43b5-94a0-09666f1c8c4c**ServerName**.xmlwhere ServerName是服务器的名称.这些文件通常很小(50kb),但有些文件大小为500kb.下一步是将异常写入日志的代码:
...
SyncLock threadlock // static variable
ExceptionPolicy.HandleException(ex, "Global Policy")
End SyncLock
...
Run Code Online (Sandbox Code Playgroud)
我无法理解为什么创建所有这些奇怪的文件.有人可以帮忙吗?
我面临的情况是我在W2k3服务器上运行的ASP.NET Web服务(.NET 3.5),该服务器使用CacheManager/IsolatedStorage存储来存储持久化状态变量.在我们更改物理机器之前,此配置已经运行了很长时间.现在,当访问该值的代码运行时,它会抛出IsolatedStorageException(在下面发布).据我所知,用户/程序集存储是正在访问的内容,执行用户是本地管理员组的成员.有没有人建议缺少什么特权?
无法创建商店目录.(HRESULT异常:0x80131468)
键入:Microsoft.Practices.ObjectBuilder2.BuildFailedException.错误:当前构建操作(构建密钥构建密钥[Microsoft.Practices.EnterpriseLibrary.Caching.ICacheManager,缓存管理器])失败:无法创建商店目录.(来自HRESULT的异常:0x80131468)(策略类型为ConfiguredObjectStrategy,索引2).跟踪:位于Microsoft.Practices的Microsoft.Practices.ObjectBuilder2.Builder.BuildUp(IReadWriteLocator定位器,ILifetimeContainer生命周期,IPolicyList策略,IStrategyChain策略,Object buildKey,Object existing)上的Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context). Microsoft的ObjectBuilder2.Builder.BuildUp [TTypeToBuild](IReadWriteLocator定位器,ILifetimeContainer生命周期,IPolicyList策略,IStrategyChain策略,Object buildKey,Object existing).1.CreateDefault()
at Microsoft.Practices.EnterpriseLibrary.Caching.CacheFactory.GetCacheManager()
at Ept.Commands.SettlementCommand.BeginSettlement() in c:\Projects\EPT\Ept.Framework.Services\Commands\SettlementCommand.cs:line 102
at Ept.Commands.SettlementCommand.ExecuteKernel(SettlementRequest request) in c:\Projects\EPT\Ept.Framework.Services\Commands\SettlementCommand.cs:line 188
at Ept.Command2.Execute(TRequest请求)在c:\ Projects\EPT\Ept.Framework.Services\Commands\Command.cs:第79行.ExecutionStrategyTypeName:ConfiguredObjectStrategy ExecutingStrategyIndex:2 BuildKey:Build Key [Microsoft.Practices.EnterpriseLibrary.Caching.ICacheManager ,缓存管理器]类型:System.IO.IsolatedStorage.IsolatedStorageException.错误:无法创建商店目录.(来自HRESULT的异常:0x80131468).跟踪:位于System.IO.IsolatedStorage上System.IO.IsolatedStorageStorageSilerageFile.GetRootDir(IsolatedStorageScope范围)中System.IO.IsolatedStorage.IsolatedStorageFile.InitGlobalsNonRoamingUser(IsolatedStorageScope范围)的System.IO.IsolatedStorage.IsolatedStorageFile.nGetRootDir(IsolatedStorageScope范围)处. System.IO.IsolatedStorage中的.SsolatedStorageFile.GetGlobalFileIOPerm(IsolatedStorageScope范围).2.Create(IBuilderContext context, TConfiguration objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.AssemblerBasedCustomFactory2.在Microsoft.Practices.EnterpriseLibrary的Microsoft.Practices.EnterpriseLibrary.Caching.Configuration.CacheManagerAssembler.Assemble(IBuilderContext context,CacheManagerDataBase objectConfiguration,IConfigurationSource configurationSource,ConfigurationReflectionCache reflectionCache)上创建(IBuilderContext上下文,String name,IConfigurationSource配置源,ConfigurationReflectionCache reflectionCache). Common.Configuration.ObjectBuilder.AssemblerBasedObjectFactory2.Create(IBuilderContext context, TConfiguration objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
at Microsoft.Practices.EnterpriseLibrary.Caching.CacheManagerCustomFactory.Create(IBuilderContext context, CacheManagerDataBase objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.AssemblerBasedCustomFactory2.在Microsoft的Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.AssemblerBasedCustomFactory`2.CreateObject(IBuilderContext context,String name,IConfigurationSource configurationSource,ConfigurationReflectionCache reflectionCache)上创建(IBuilderContext …
我们正在使用企业库4.1和智能客户端软件工厂2008来申请.我们如何将企业库5.0和SCSF 2010升级到我们的应用程序.目前我们正在使用visual studio 2008.
要升级需要注意的事情.
早期的帮助将不胜感激.
我一直在按照"Microsoft Enterprise Library 5.0"文档中的步骤创建一个HTTP模块,以将对Enterprise Library容器的引用注入到ASP.NET Web应用程序的页面中.
它包含以下代码(也可在此处在线显示):
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using Microsoft.Practices.Unity;
namespace Unity.Web
{
public class UnityHttpModule : IHttpModule
{
public void Init(HttpApplication context)
{
context.PreRequestHandlerExecute += OnPreRequestHandlerExecute;
}
public void Dispose() { }
private void OnPreRequestHandlerExecute(object sender, EventArgs e)
{
IHttpHandler currentHandler = HttpContext.Current.Handler;
HttpContext.Current.Application.GetContainer().BuildUp(
currentHandler.GetType(), currentHandler);
// User Controls are ready to be built up after page initialization is complete
var currentPage = HttpContext.Current.Handler as Page;
if (currentPage != null) …Run Code Online (Sandbox Code Playgroud)