The Log4Net mailing list is a great source of information about using log4Net, in this forum we collect all the messages in the log4net user list and some selected threads from the developer list.
| Author |
Messages |
|
Paul Franklin
 |
| 11/05/2008 1:04 PM |
|
I am trying to log to a Network Drive using a RollingFileAppender but am having problems. When I set the file parameter value to a UNC value (\\servername\sharename\Alert.txt) it works fine However, when I try to set it to a mapped drive value which refers to the same path it fails. The internal debug is showing this: log4net:ERROR [RollingFileAppender] No output stream or file set for the appender named [TDALog]. log4net: FileAppender: Opening file for writing [T:\Alert.txt] append [True] log4net:ERROR [RollingFileAppender] Unable to acquire lock on file T:\Alert.txt. Could not find a part of the path 'T:\'. log4net:ERROR [RollingFileAppender] OpenFile(T:\Alert.txt,True) call failed. log4net.Appender.FileAppender+LockingStream+LockStateException: The file is not currently locked at log4net.Appender.FileAppender.LockingStream.get_CanWrite() at System.IO.StreamWriter..ctor(Stream stream, Encoding encoding, Int32 bufferSize) at System.IO.StreamWriter..ctor(Stream stream, Encoding encoding) at log4net.Appender.FileAppender.OpenFile(String fileName, Boolean append) at log4net.Appender.RollingFileAppender.OpenFile(String fileName, Boolean append) at log4net.Appender.FileAppender.SafeOpenFile(String fileName, Boolean append) log4net:ERROR [RollingFileAppender] No output stream or file set for the appender named [TDALog]. When I use UNC for the same file it works okay: log4net: FileAppender: Opening file for writing [\\uncdrive\share\Alert.txt] append [True] log4net: XmlHierarchyConfigurator: Created Appender [TDALog] log4net: XmlHierarchyConfigurator: Adding appender named [TDALog] to logger [root]. log4net: XmlHierarchyConfigurator: Retrieving an instance of log4net.Repository.Logger for logger [tda]. log4net: XmlHierarchyConfigurator: Setting [trustda] additivity to [True]. log4net: XmlHierarchyConfigurator: Logger [trustda] Level string is [DEBUG]. log4net: XmlHierarchyConfigurator: Logger [trustda] level set to [name="DEBUG",value=30000]. log4net: XmlHierarchyConfigurator: Adding appender named [TDALog] to logger [tda]. Any ideas? We would only use UNC as a last resort because the application is going to be distributed to multiple sites which all use a common drive mapping letter
Click here for FREE customisable desktop wallpapers. Get them Now!
Read amazing stories to your kids on Messenger Try it Now! |
|
|
|
|
Steve Wagner
 |
| 11/06/2008 7:08 AM |
|
May i am wrong, but as far as i know are mapped network drives only visible for the current which created it and not for the entry system. UNC Pathes are the most common way to access a network share.
Steve
|
|
|
|
|
Paul Franklin
 |
| 11/10/2008 10:57 AM |
|
Steve, I am aware that mapped drives are only visible to the current user. Our Windows service is started using a specific user account and our VB.NET application is able to cope with reading in configuration files (including the log4net.xml file itself) from a UNC or mapped drive using the following bit of code: Private Sub New(ByVal configFile As String) 'check that the config file is mapped drive ConfigurationFileDetails = configFile If Not configFile.StartsWith("\\") Then 'convert mapped drive letter Dim search As New Management.ManagementObjectSearcher("SELECT RemoteName FROM win32_NetworkConnection WHERE LocalName = """ + configFile.Substring(0, 2) + """") Dim remoteName As String Dim mgmtObjCollection As Management.ManagementObjectCollection = search.Get() For Each mgmtObj As Management.ManagementObject In mgmtObjCollection remoteName = mgmtObj("RemoteName").ToString If Not IsNothing(remoteName) Then remoteName += configFile.Substring(2) ConfigurationFileDetails = remoteName End If Next End If I was hoping that there might be something similar in log4net itself? Paul
|
|
|
|
|
Dag Christensen
 |
| 11/10/2008 12:30 PM |
|
I don't think I understand what the problem is?
You're saying writing to UNC is fine, while log4net complains about T: being unavailable? As Steve says, this indicates that T: isn't mapped for the logged on user (did the login script run successfully?)
Re your code below: If T: and the UNC path both points to the same folder for the logged on user, why would you (or log4net) want to translate T: to its equivalent UNC path?
Have you tried writing directly to "T:\" from your service? (from outside log4net)
I don't think you'll see usage of WMI in core log4net. I haven't tried this myself, but I believe you can override RollingFileAppender's File {get; set; } if you want to implement the code you posted.
Best wishes,
Dag
|
|
|
|
|
|
| You are not authorized to post a reply. |
|
|
|
ActiveForums 3.7
|