NLog Target Extension
NLogのTargetをIsolatedStorageFileにしたくて調べていたのだが、中々上手く行かん。 他のアセンブリからターゲットクラスを呼び出す時点でエラーが出てしまう。
NLog.config
<?xml version="1.0" encoding="utf-8" ?> <nlog> <extensions> <add assembly="Mandarine"/> </extensions> <targets> <target name="target1" type="IsolatedStorage" layout="${longdate} ${callsite} ${level} ${message}"/> </targets> <rules> <logger name="*" minlevel="Debug" writeTo="target1" /> </rules> </nlog>
IsolatedStorageTarget.cs
[Target("IsolatedStorage")] public class IsolatedStorageTarget : TargetWithLayout { public IsolatedStorageTarget() : base() { } protected override void Write(LogEventInfo logEvent) { if (!System.ComponentModel.DesignerProperties.IsInDesignTool) { using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication()) { using (Stream stream = new IsolatedStorageFileStream("Mandarine.log" , FileMode.Append, FileAccess.Write, store)) { var writer = new StreamWriter(stream); writer.WriteLine(this.Layout.Render(logEvent)); } } } } }
うーむ。 また調べ物の時間だ。
NLog.NLogConfigurationException はハンドルされませんでした。 Message=Exception occurred when loading configuration from NLog.config StackTrace: at NLog.Config.XmlLoggingConfiguration.Initialize(XmlReader reader, String fileName, Boolean ignoreErrors) at NLog.Config.XmlLoggingConfiguration..ctor(String fileName) at NLog.LogFactory.get_Configuration() at NLog.LogFactory.GetLogger(LoggerCacheKey cacheKey) at NLog.LogFactory.GetLogger(String name) at NLog.LogManager.GetCurrentClassLogger() :