[CSharp]向日志中写日志的代码,这样的代码能给打几分呢?


WriteAppEventLog.cs
ExpandedBlockStart.gif ContractedBlock.gif /**/ /********************************************************************
InBlock.gif    created:    2006/03/30
InBlock.gif    created:    30:3:2006   15:42
InBlock.gif    file ext:    cs
InBlock.gif    author:        xuzhong
InBlock.gif    
InBlock.gif    purpose:    实现向应用程序日志中写日志
ExpandedBlockEnd.gif********************************************************************
*/

None.gif
None.gif
using  System;
None.gif
None.gif
namespace  XZSoftware.App.ZhengJun
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
public class WriteEventLog
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
public WriteEventLog()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
InBlock.gif
InBlock.gif        
public static int Main(string[] args)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
int argsLength = args.Length;
InBlock.gif            
if( argsLength != 4 )
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Purging();
InBlock.gif                
return 1;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
string source  = args[0];
InBlock.gif                
string message = args[1];
InBlock.gif                
string type    = args[2];
InBlock.gif                
string id      = args[3];
InBlock.gif
InBlock.gif                
try
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    System.Diagnostics.EventLog.WriteEntry(
InBlock.gif                        source , message , GetEventType(type) , 
int.Parse(id) );
InBlock.gif                    
return 0;
ExpandedSubBlockEnd.gif                }
catch
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
return -1;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
InBlock.gif        
public static System.Diagnostics.EventLogEntryType GetEventType( string type )
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
switch( type.ToLower())
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif            
case "error":
InBlock.gif                
return System.Diagnostics.EventLogEntryType.Error;
InBlock.gif            
case "warning":
InBlock.gif                
return System.Diagnostics.EventLogEntryType.Warning;
InBlock.gif            
case "failureaudit":
InBlock.gif                
return System.Diagnostics.EventLogEntryType.FailureAudit;
InBlock.gif            
case "information":
InBlock.gif                
return System.Diagnostics.EventLogEntryType.Information;
InBlock.gif            
case "successaudit":
InBlock.gif                
return System.Diagnostics.EventLogEntryType.SuccessAudit;
InBlock.gif            
default:
InBlock.gif                
return System.Diagnostics.EventLogEntryType.Error;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public static void Purging()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            Console.WriteLine(
"");
InBlock.gif            Console.WriteLine(
"");
InBlock.gif            Console.WriteLine(
"********************************************************************");
InBlock.gif            Console.WriteLine(
"created:    2006/03/30");
InBlock.gif            Console.WriteLine(
"created:    30:3:2006   15:42");
InBlock.gif            Console.WriteLine(
"file ext:    cs");
InBlock.gif            Console.WriteLine(
"author:        xuzhong");
InBlock.gif            Console.WriteLine(
"    ");
InBlock.gif            Console.WriteLine(
"purpose:    实现向应用程序日志中写日志");
InBlock.gif            Console.WriteLine(
"*********************************************************************");
InBlock.gif            Console.WriteLine(
"");
InBlock.gif            Console.WriteLine(
"");
InBlock.gif            Console.WriteLine(
"WriteAppEventLog.exe <source> <message> <type> <id>");
InBlock.gif            Console.WriteLine(
"source  : 源");
InBlock.gif            Console.WriteLine(
"message : 内容信息");
InBlock.gif            Console.WriteLine(
"type    : 日志类型 ( Error | Warning | Information | SuccessAudit | FailureAudit )");
InBlock.gif            Console.WriteLine(
"id      : 标识错误的ID");
InBlock.gif            Console.WriteLine(
"");
InBlock.gif            Console.Write    (
"Sample  : ");
InBlock.gif            Console.WriteLine(
"WriteAppEventLog.exe \"My_Application\" \"This is a test.\" \"Error\" \"1000\"");
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

build.bat
None.gif csc  / t:exe  * .cs

能打个几分呢?
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值