保存我的操作日志

将所有的操作先保存在string  strOper中,然后将strOper保存到txt文件中。
 其中:
private string strOper=System.DateTime.Now.ToString()+"\r\n";
用来记录当前时间。'\r\n'实现在txt文件中的换行。

ContractedBlock.gif ExpandedBlockStart.gif      /***记录操作日志***/ #region /***记录操作日志***/
InBlock.gif        
private   void   WriteLog()   
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{  
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//判断路径是否存在,不存在创建
InBlock.gif
                string dir=System.IO.Path.GetDirectoryName(logPath);
InBlock.gif                
if(!Directory.Exists(dir))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    Directory.CreateDirectory(dir);
ExpandedSubBlockEnd.gif                }

InBlock.gif
InBlock.gif
//                StreamWriter   sw   =   new   StreamWriter(logPath,false,System.Text.Encoding.Unicode); //不追加
InBlock.gif
                StreamWriter   sw   =   new   StreamWriter(logPath,true);  //追加
InBlock.gif
                sw.WriteLine(strOper.ToString());
InBlock.gif                    
InBlock.gif                sw.Close();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch (Exception err)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                MessageBox.Show(
this,err.Message,"保存操作日志",MessageBoxButtons.OK,MessageBoxIcon.Information);
ExpandedSubBlockEnd.gif            }

InBlock.gif           
ExpandedSubBlockEnd.gif        }

ExpandedBlockEnd.gif        
#endregion


ContractedBlock.gif ExpandedBlockStart.gif /***查看操作日志***/ #region /***查看操作日志***/
InBlock.gif        
private void btnDetails_Click(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if(File.Exists(this.logPath))
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
try
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    System.Diagnostics.Process.Start(
"notepad.exe",logPath);
InBlock.gif
ExpandedSubBlockEnd.gif                }

InBlock.gif                
catch(Exception err)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    MessageBox.Show(
this,err.Message,"打开操作日志",MessageBoxButtons.OK,MessageBoxIcon.Information);
ExpandedSubBlockEnd.gif                }

InBlock.gif  
ExpandedSubBlockEnd.gif            }

InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedBlockEnd.gif        
#endregion

转载于:https://www.cnblogs.com/flashicp/archive/2007/08/07/846456.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值