Windows Phone 實用開發技巧(24):上傳日誌

來源:互聯網
上載者:User

In my last post《Windows Phone 實用開發技巧(22):使用日誌記錄當前資訊與異常資訊》 , I talked about how to log in our application. Here comes the problem: how can we get the log file. If we run application locally, we can use ISETool to get files stored in IsolatedStorage. But since app users are far away from you. We cannot go to somebody and say “Hey, can I use your phone to get my log back…bala..bala..”

We can make a button that is used to let user to upload logs, use vdisk as destination. We can rename log files with time so that we can distinguish when the log file sent to our space. Here I built a demo app use vdisk and logging library to demonstrate how to upload log files to vdisk.

1. Create a new project named:mangoUploadLog, add essential libs to it

2.Edit App.xaml.cs, add some log in it. We log the lifecycle of the app

// Code to execute when the application is launching (eg, from Start)        // This code will not execute when the application is reactivated        private void Application_Launching(object sender, LaunchingEventArgs e)        {            LoggingHelper.Log("Application_Launching....");        }        // Code to execute when the application is activated (brought to foreground)        // This code will not execute when the application is first launched        private void Application_Activated(object sender, ActivatedEventArgs e)        {            LoggingHelper.Log("Application_Activated....");        }        // Code to execute when the application is deactivated (sent to background)        // This code will not execute when the application is closing        private void Application_Deactivated(object sender, DeactivatedEventArgs e)        {            LoggingHelper.Log("Application_Deactivated....");        }        // Code to execute when the application is closing (eg, user hit Back)        // This code will not execute when the application is deactivated        private void Application_Closing(object sender, ClosingEventArgs e)        {            LoggingHelper.Log("Application_Closing....");        }

3.Edit MainPage.xaml, add a Button named ”Upload” to UI

4.Edit Upload Button Click event, add following code:

private void btnUpload_Click(object sender, RoutedEventArgs e)        {            //login            NetService net = new NetService();            Constants.AppKey = "<your_appkey>";            Constants.AppSecret = "<your_appsecret>";            net.ServicecallBack = LoginCallback;        }        private void LoginCallback(bool isSuccess, object response, string errormsg)        {            if (isSuccess)//if success, upload file            {                NetService net = new NetService();                Constants.AppKey = "<your_appkey>";                Constants.AppSecret = "<your_appsecret>";                net.ServicecallBack = NetCallback;                net.Upload(new UploadFileReq                    {                         FileName="log.dat",                         IsCover="yes",                          SourceFolder="/log.data"                    });            }            else            {                Deployment.Current.Dispatcher.BeginInvoke(delegate                {                    MessageBox.Show(errormsg);                });            }        }

5. Test our app, run it and click upload, then login vdisk, you will find your log file there

Hope this helps, thanks for reading. You can find source code here.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.