iceboxnet and Ice.LogFile

ggslayerggslayer Member MingYi ZhangOrganization: renren.comProject: renren data platform

We recently started writing IceBox sevice by C#. We found that if we put the property Ice.LogFile in config, the service caught exception and the log line has been written into the log file specified by Ice.LogFile:
!! 2017/7/20 18:28:01:242 iceboxnet.exe: error: ServiceManager: caught exception:
System.IO.IOException: file “d:\temp\hello.log” been used by another process,can not access this file.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at Ice.FileLoggerI..ctor(String prefix, String file) position d:\3.6.1.1\dist-utils\build\ice-v3.6.1-msvc2015\builds\VC120-x86-release\csharp\src\Ice\LoggerI.cs:line 130
at Ice.FileLoggerI.cloneWithPrefix(String prefix) position d:\3.6.1.1\dist-utils\build\ice-v3.6.1-msvc2015\builds\VC120-x86-release\csharp\src\Ice\LoggerI.cs:line 135
at IceBox.ServiceManagerI.startService(String service, String entryPoint, String[] args)
at IceBox.ServiceManagerI.run()

After debugging the starting procedure of IceBox service, I thought i found the reason.
At LoggerI.cs:127, FileLoggerI defined as:
public FileLoggerI(string prefix, string file) :
base(prefix)
{
_file = file;
_writer = new StreamWriter(new FileStream(file, FileMode.Append, FileAccess.Write, FileShare.None));
}

    public override Logger cloneWithPrefix(string prefix)
    {
        return new FileLoggerI(prefix, _file);
    }

When iceboxnet starting, Applicaion creates it's static communicator with logger, then the log file is opened, but the share mode is none. That's mean that file can not be opened again even in same process. When starting service, at ServiceManagerI.cs:590:
if(initData.properties.getProperty("Ice.LogFile").Length == 0 &&
(initData.properties.getPropertyAsInt("Ice.UseSyslog") <= 0 ||
IceInternal.AssemblyUtil.platform_ == IceInternal.AssemblyUtil.Platform.Windows))
{
initData.logger = _logger.cloneWithPrefix(initData.properties.getProperty("Ice.ProgramName")); --> exception
}
cloneWithPrefix will throw exception beacuse it open the same file that already opened with share mode none.

Comments

  • xdmxdm La Coruña, SpainAdministrators, ZeroC Staff Jose Gutierrez de la ConchaOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff

    Hi Zhang,

    Thanks for reporting the issue, I have push a fix to use ReadWrite shared mode when open the file in the logger

Sign In or Register to comment.