Logger - TextWriter.WriteLine is not supported

Please post public support tickets here. Note: for private support tickets, please send an email to support@cshtml5.com instead.
sd1388
Posts: 34
Joined: Mon Jan 30, 2017 9:51 am

Logger - TextWriter.WriteLine is not supported

Postby sd1388 » Tue Jun 13, 2017 11:28 pm

Hi Team,

I am implementing logger mechanism in project. It gives error when below code is used.

Code: Select all

using (StreamWriter objWrite = new StreamWriter(strFolderpath + "//Log_", true, Encoding.UTF8))
{
        objWrite.WriteLine(DateTime.Now.ToString() + " : "+ strMessage);
}


Please suggest.

Thanks.

JS-Support @Userware
Site Admin
Posts: 1142
Joined: Tue Apr 08, 2014 3:42 pm

Re: Logger - TextWriter.WriteLine is not supported

Postby JS-Support @Userware » Wed Jun 14, 2017 4:08 am

Hi,

Please find below some sample code to read/write from/to the IsolatedStorage (note: other locations are not allowed due to web browser security restrictions).


1. Sample code using the IsolatedStorage class:

XAML code:

Code: Select all

<StackPanel>
    <TextBox x:Name="TextBoxFileStorageDemo" Text="Enter some text"/>
    <Button Content="Save to file using the IsolatedStorageFile class" Click="ButtonSaveToIsolatedStorageFile_Click"/>
    <Button Content="Load from file using the IsolatedStorageFile class" Click="ButtonLoadFromIsolatedStorageFile_Click"/>
</StackPanel>


C# code:

Code: Select all

private void ButtonSaveToIsolatedStorageFile_Click(object sender, RoutedEventArgs e)
{
    string fileName = "SampleFile.txt";
    string data = TextBoxFileStorageDemo.Text;
    using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForAssembly())
    {
        IsolatedStorageFileStream fs = null;
        using (fs = storage.CreateFile(fileName))
        {
            if (fs != null)
            {
                Encoding encoding = new UTF8Encoding();
                byte[] bytes = encoding.GetBytes(data);
                fs.Write(bytes, 0, bytes.Length);
                fs.Close();
                MessageBox.Show("A new file named SampleFile.txt was successfully saved to the storage.");
            }
            else
                MessageBox.Show("Unable to save the file SampleFile.txt to the storage.");
        }
    }
}

private void ButtonLoadFromIsolatedStorageFile_Click(object sender, RoutedEventArgs e)
{
    string fileName = "SampleFile.txt";
    using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForAssembly())
    {
        if (storage.FileExists(fileName))
        {
            using (IsolatedStorageFileStream fs = storage.OpenFile(fileName, System.IO.FileMode.Open))
            {
                if (fs != null)
                {
                    using (StreamReader sr = new StreamReader(fs))
                    {
                        string data = sr.ReadToEnd();
                        MessageBox.Show("The following text was read from the file SampleFile.txt located in the storage: " + data);
                    }
                }
                else
                    MessageBox.Show("Unable to load the file SampleFile.txt from the storage.");
            }
        }
        else
            MessageBox.Show("No file named SampleFile.txt was found in the storage.");
    }
}



2. Sample code using the FileInfo class:

XAML code:

Code: Select all

<StackPanel>
    <TextBox x:Name="TextBoxFileStorageDemo" Text="Enter some text"/>
    <Button Content="Save to file using the FileInfo class" Click="ButtonSaveToFileInfo_Click"/>
    <Button Content="Load from file using the FileInfo class" Click="ButtonLoadFromFileInfo_Click"/>
    <Button Content="Delete file using the FileInfo class" Click="ButtonDeleteFileInfo_Click"/>
</StackPanel>


C# code:

Code: Select all

private void ButtonSaveToFileInfo_Click(object sender, RoutedEventArgs e)
{
    string fileName = "Test.txt";
    string data = TextBoxFileStorageDemo.Text;
    FileInfo fileInfo = new FileInfo(fileName);
    using (FileStream fs = fileInfo.OpenWrite())
    {
        Encoding encoding = new UTF8Encoding();
        byte[] bytes = encoding.GetBytes(data);
        fs.Write(bytes, 0, bytes.Length);
        fs.Close();
        MessageBox.Show("A new file named Test.txt was successfully saved to the storage.");
    }
}

private void ButtonLoadFromFileInfo_Click(object sender, RoutedEventArgs e)
{
    string fileName = "Test.txt";
    FileInfo fileInfo = new FileInfo(fileName);
    if (fileInfo.Exists)
    {
        using (FileStream fs = fileInfo.OpenRead())
        {
            if (fs != null)
            {
                using (StreamReader sr = new StreamReader(fs))
                {
                    string data = sr.ReadToEnd();
                    MessageBox.Show("The following text was read from the file Test.txt located in the storage: " + data);
                }
            }
            else
                MessageBox.Show("Unable to load the file Test.txt from the storage.");
        }
    }
    else
        MessageBox.Show("No file named Test.txt was found in the storage.");
}

private void ButtonDeleteFileInfo_Click(object sender, RoutedEventArgs e)
{
    string fileName = "Test.txt";
    FileInfo fileInfo = new FileInfo(fileName);
    fileInfo.Delete();
    MessageBox.Show("The file named Test.txt was successfully deleted from the local page storage.");
}



Regards,
JS-Support


Return to “Technical Support”

Who is online

Users browsing this forum: No registered users and 4 guests

 

 

cron