RemotingConfiguration锁定我的文件,如何使用log4net的RemotingAppender?

时间:2013-09-24 08:26:43

标签: c# log4net remoting

client.cs

    RemotingAppender remotingAppender = new RemotingAppender();
    remotingAppender.Sink = "tcp://localhost:15642/LoggingSinkInConsoleDaemon";
    remotingAppender.BufferSize = 1;
    remotingAppender.ActivateOptions();
    BasicConfigurator.Configure(remotingAppender);
    log.Info("everything is ok!");

server.cs

    LogManager.GetRepository().PluginMap.Add(new Plugin.RemoteLoggingServerPlugin("LoggingSinkInConsoleDaemon"));

client.exe登录到server.exe,一切正常,在client.exe退出后,我使用Unlocker.exe(可以找到here)发现client.exe被server.exe锁定(这意味着我无法删除client.exe,因为它被server.exe使用),我找到了由RemotingAppender引起的错误,但我不知道如何解决。

我认为Remoting处理了RemotingAppender的请求,并且它已经锁定了client.exe,我该如何释放锁?

======================更新1 ======================= ============

client.cs

    var repo = LogManager.GetRepository();
    var app = repo.GetAppenders().Where(x => x.GetType() == typeof(RemotingAppender)).FirstOrDefault();
    var remotingAppender = app as RemotingAppender;

    var root = ((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Root;
    var attachable = root as IAppenderAttachable;
    attachable.RemoveAppender(remotingAppender);

我在上面尝试过,但是我丢失了我的日志。

我搜索源代码,RemoveAppender从列表中删除记录器,所以它没有解决问题

1 个答案:

答案 0 :(得分:0)

我根本不确定你是否尝试过remotingAppender.Close();当你完成它?