zoukankan      html  css  js  c++  java
  • Windows Phone 实用开发技巧(24):上传日志

    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

    image

    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

    image

    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.

    如果您喜欢我的文章,您可以通过支付宝对我进行捐助,您的支持是我最大的动力https://me.alipay.com/alexis


    作者:Alexis
    出处:http://www.cnblogs.com/alexis/
    关于作者:专注于Windows Phone 7、Silverlight、Web前端(jQuery)。
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,如有问题,可以通过shuifengxuATgmail.com  联系我,非常感谢。

  • 相关阅读:
    什么是数据集
    Fastreport使用经验(转)在Delphi程序中访问报表对象
    多步操作产生错误,请检查每一步的状态值
    删除整个目录
    Win7下虚拟机个人使用小结:Virtual PC,VMware和VirtualBox
    Ribbon_窗体_实现Ribbon风格的窗体
    数学建模python matlab 编程(椭圆声学原理画图证明,解析几何)
    数学建模python matlab 编程(指派问题)
    matlab中如何给一个矩阵中的某几个特定位置赋值
    python matlab 带包实现全排列
  • 原文地址:https://www.cnblogs.com/alexis/p/2206535.html
Copyright © 2011-2022 走看看