|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
elearning info not workingto write to a debug log use the following: 'd. FileInfo fi = new FileInfo(@"c:\application.log"); ' StreamWriter sw = fi.AppendText(); I can't seem to convert that to vb successfully Dim fi As FileInfo = New FileInfo(m_DebugFileName) 'this didn't work Dim sw As StreamWriter = New StreamWriter(fi.AppendText()) 'so i tried this and still no joy Dim sw As StreamWriter = New StreamWriter(fi) Error 1 Overload resolution failed because no accessible 'New' can be called with these arguments: 'Public Sub New(path As String)': Value of type 'System.IO.FileInfo' cannot be converted to 'String'. 'Public Sub New(stream As System.IO.Stream)': Value of type 'System.IO.FileInfo' cannot be converted to 'System.IO.Stream'. plus i see no where to pass the text i want to write to the file any help? thanks mark Am 11.06.2010 03:16, schrieb mp:
> according to online elearning (ms) Did you> to write to a debug log use the following: > 'd. FileInfo fi = new FileInfo(@"c:\application.log"); > > ' StreamWriter sw = fi.AppendText(); > > I can't seem to convert that to vb successfully > > Dim fi As FileInfo = New FileInfo(m_DebugFileName) import System.IO ? > 'this didn't work Dim sw As StreamWriter = fi.AppendText()> > Dim sw As StreamWriter = New StreamWriter(fi.AppendText()) The AppendText function already creates a FileStream and returns a StreamWriter writing into the stream. It's the same as Dim sw As New StreamWriter(fi.FullName, True) (I don't know why it's called "AppendText". You could append everything.) > 'so i tried this and still no joy Dim sw As StreamWriter = New StreamWriter(fi.fullname)> > Dim sw As StreamWriter = New StreamWriter(fi) > Error 1 Overload resolution failed because no accessible 'New' can be called I don't see it, too. ;-)> with these arguments: > 'Public Sub New(path As String)': Value of type 'System.IO.FileInfo' > cannot be converted to 'String'. > 'Public Sub New(stream As System.IO.Stream)': Value of type > 'System.IO.FileInfo' cannot be converted to 'System.IO.Stream'. > plus i see no where to pass the text i want to write to the file > > any help? sw.writeline("yadda") There are several ways to write to a file. For example: Using fs = fi.Open(FileMode.Append, FileAccess.Write, FileShare.Read) Using sw As New StreamWriter(fs, System.Text.Encoding.Default) sw.WriteLine("abc") End Using End Using Or, if you just want to open, write, close a/to a file: File.AppendAllText(Path, "abc", System.Text.Encoding.Default) -- Armin
Show quote
Hide quote
"Armin Zingler" <az.nospam@freenet.de> wrote in message yes, otherwise the error would have been missing reference or something?news:OLzJ2wQCLHA.3880@TK2MSFTNGP04.phx.gbl... > Am 11.06.2010 03:16, schrieb mp: >> according to online elearning (ms) >> to write to a debug log use the following: >> 'd. FileInfo fi = new FileInfo(@"c:\application.log"); >> >> ' StreamWriter sw = fi.AppendText(); >> >> I can't seem to convert that to vb successfully >> >> Dim fi As FileInfo = New FileInfo(m_DebugFileName) > > Did you > import System.IO > ? Show quoteHide quote > Hi Armin,> >> 'this didn't work >> >> Dim sw As StreamWriter = New StreamWriter(fi.AppendText()) > > > Dim sw As StreamWriter = fi.AppendText() > > The AppendText function already creates a FileStream and returns > a StreamWriter writing into the stream. It's the same as > > Dim sw As New StreamWriter(fi.FullName, True) > > > (I don't know why it's called "AppendText". You could append everything.) > >> 'so i tried this and still no joy >> >> Dim sw As StreamWriter = New StreamWriter(fi) > > Dim sw As StreamWriter = New StreamWriter(fi.fullname) > >> Error 1 Overload resolution failed because no accessible 'New' can be >> called >> with these arguments: >> 'Public Sub New(path As String)': Value of type 'System.IO.FileInfo' >> cannot be converted to 'String'. >> 'Public Sub New(stream As System.IO.Stream)': Value of type >> 'System.IO.FileInfo' cannot be converted to 'System.IO.Stream'. > > > >> plus i see no where to pass the text i want to write to the file >> >> any help? > > I don't see it, too. ;-) > > sw.writeline("yadda") > > > There are several ways to write to a file. For example: > > Using fs = fi.Open(FileMode.Append, FileAccess.Write, > FileShare.Read) > Using sw As New StreamWriter(fs, System.Text.Encoding.Default) > sw.WriteLine("abc") > End Using > End Using > > > Or, if you just want to open, write, close a/to a file: > > File.AppendAllText(Path, "abc", System.Text.Encoding.Default) > > > -- > Armin That last line is how i've been doing it previously. when the elearning lesson said it should be the other way i thought i'd try that. ' 'Start e-learning question '****************** 'You are developing a logging module for a large application by using the '.NET Framework. 'You need to append logging information to a file named application.log. This 'log file is opened when the application is started and is closed only when 'the application is closed. However, you append text several times to the 'file during a session. 'You must minimize overhead to the logging process to ensure maximum 'performance. 'Which code segment should you use to create the log file? 'a. StreamWriter sw = File.CreateText(@"c:\application.log"); 'b. FileInfo fi = new FileInfo(@"c:\application.log"); ' FileStream fs = fi.Open(FileMode.Append); 'c. StreamWriter sw = File.AppendText(@"c:\application.log"); 'd. FileInfo fi = new FileInfo(@"c:\application.log"); ' StreamWriter sw = fi.AppendText(); it said the correct answer was d. ps, what is the meaning of @ in those arguments? thanks mark
Show quote
Hide quote
"mp" <nospam@thanks.com> wrote in message cuious what's the difference between that and just doingnews:hus7uf$7ht$1@news.eternal-september.org... > > "Armin Zingler" <az.nospam@freenet.de> wrote in message > news:OLzJ2wQCLHA.3880@TK2MSFTNGP04.phx.gbl... >> Am 11.06.2010 03:16, schrieb mp: >>> according to online elearning (ms) >>> to write to a debug log use the following: >>> 'd. FileInfo fi = new FileInfo(@"c:\application.log"); SNIP >> >> There are several ways to write to a file. For example: >> >> Using fs = fi.Open(FileMode.Append, FileAccess.Write, >> FileShare.Read) >> Using sw As New StreamWriter(fs, System.Text.Encoding.Default) >> sw.WriteLine("abc") >> End Using >> End Using >> Dim sw As StreamWriter = New StreamWriter(m_DebugFileName, True) sw.WriteLine(strMsg) sw.Close() what is the FileInfo object doing other than passing the filename which you already have? Am 11.06.2010 05:08, schrieb mp:
Show quoteHide quote >>> There are several ways to write to a file. For example: Nothing special. Just took it because you've mentioned it before. If>>> >>> Using fs = fi.Open(FileMode.Append, FileAccess.Write, >>> FileShare.Read) >>> Using sw As New StreamWriter(fs, System.Text.Encoding.Default) >>> sw.WriteLine("abc") >>> End Using >>> End Using >>> > > cuious what's the difference between that and just doing > > Dim sw As StreamWriter = New StreamWriter(m_DebugFileName, True) > > sw.WriteLine(strMsg) > > sw.Close() > > what is the FileInfo object doing other than passing the filename which you > already have? you don't need 'fi', just use the path (String). -- Armin Am 11.06.2010 04:44, schrieb mp:
Show quoteHide quote >>> according to online elearning (ms) yes, something. You didn't write what the problem was, so I guessed. :)>>> to write to a debug log use the following: >>> 'd. FileInfo fi = new FileInfo(@"c:\application.log"); >>> >>> ' StreamWriter sw = fi.AppendText(); >>> >>> I can't seem to convert that to vb successfully >>> >>> Dim fi As FileInfo = New FileInfo(m_DebugFileName) >> >> Did you >> import System.IO >> ? > > yes, otherwise the error would have been missing reference or something? >> Or, if you just want to open, write, close a/to a file: Probably because the question was how to _create_ the log file, not how>> >> File.AppendAllText(Path, "abc", System.Text.Encoding.Default) >> >> > > Hi Armin, > That last line is how i've been doing it previously. > when the elearning lesson said it should be the other way i thought i'd try > that. to write into it. File.AppendAllText above opens, writes, closes the file. For logging I'd prefer File.AppendAllText because, if the app crashes, the write buffer hasn't been flushed to disk. Therefore some content is missing, which is not helpful for logging, maybe for finding errors. (but that was not the "e-learning question".) Show quoteHide quote > ' If I enter it in the help index, it finds "@ (string literal)"> 'Start e-learning question > > '****************** > > 'You are developing a logging module for a large application by using the > > '.NET Framework. > > 'You need to append logging information to a file named application.log. > This > > 'log file is opened when the application is started and is closed only when > > 'the application is closed. However, you append text several times to the > > 'file during a session. > > 'You must minimize overhead to the logging process to ensure maximum > > 'performance. > > 'Which code segment should you use to create the log file? > > 'a. StreamWriter sw = File.CreateText(@"c:\application.log"); > > 'b. FileInfo fi = new FileInfo(@"c:\application.log"); > > ' FileStream fs = fi.Open(FileMode.Append); > > 'c. StreamWriter sw = File.AppendText(@"c:\application.log"); > > 'd. FileInfo fi = new FileInfo(@"c:\application.log"); > > ' StreamWriter sw = fi.AppendText(); > > > > it said the correct answer was d. > ps, what is the meaning of @ in those arguments? -- Armin
in dotnet ide can you return to previous position
logging to text file and opening at end of program Creating an event by force. Make a component on runtime. Inheritance and COM checking whether the current object is a specific class. Datagridview selected rows ToolStrip - how I can make rectangle on the last selected item ? ToolStrip. VS 2008 Windows Forms project will not start |
|||||||||||||||||||||||