ここで答えた以上のものだと思います:
C#で属性を動的に追加できますか?
アセンブリ レベルの属性と構成キーをバインドする必要がある理由はまだわかりませんが、構成キーを属性のコンストラクター/プロパティに渡し、その値を属性ロジック内で解決できます。次のようになります。
[AttributeUsage(AttributeTargets.Assembly)]
public class TraceAttribute : Attribute
{
public TraceAttribute(string traceConfigKey)
{
var keyValue = ConfigurationManager.AppSettings[traceConfigKey];
DoTracing = !string.IsNullOrEmpty(keyValue) && bool.Parse(keyValue);
}
/// <summary>
/// Use this property for your tracing conditional logic.
/// </summary>
public bool DoTracing { get; private set; }
}
次に、AssemblyInfo で:
[assembly: Trace("DoTracing")]
そして設定ファイル:
<appSettings>
<add key="DoTracing" value="true"/>
</appSettings>
別の解決策として、既存の属性を使用し、それをカスタマイズできない場合は、条件付きコンパイル シンボルをプロジェクト プロパティに追加して、次のように記述することもできます。
#if TRACE
[assembly: Trace()]
#endif
もちろん、プロジェクトの再コンパイルが必要です。